Search code examples
javascriptfrpbacon.js

Output list of items with baconjs


Can you suggest a better way to render list of items on my page with baconjs. I need opportunity to add/delete/change elements inside this list. List of items should be a property, modified by events? Or something other?


Solution

  • Bacon.update (https://github.com/baconjs/bacon.js/#bacon-update) can be used to update the list based on multiple source events like add/update/delete. You might want to try something like this:

    var itemsP = Bacon.update(
        [],
        addE, (items, newItem) => items.concat(newItem),
        removeE, (items, removedItem) => items = items.filter((i) => i != removedItem)
    );
    

    Here's a fiddle that demonstrates this in action: https://jsfiddle.net/1w2brL1e/1/