And I’m adding a user to the items Observable like this:
items.add(Contenxt.getUser(id));
Now I’m not sure how I could add the Position to this structure. With your code, it will create empty items, which have a position and items with content but without a position.
I don’t want to add an entry “Position” for a user in my database, because the Position will often change.
You could do away with a reactive mapping in this case.
I didn’t test the code below, but it should be pretty close:
var mapped = items.map(function(item,index) { // this here basically subscribes to updates in items variable, and loops through it every time items value changes
item.position = index; // this here adds a new property called "position" to the item object, so make sure you do not use a name already present in the object
return item; // and then it returns the slightly modified item at its position
});
// in the very end, mapped looks just like items, with an added "position" property to every object
// and it updates behind-the-scenes with every change to items
and when you have that, add the mapped variable to your module.exports and use it instead of items.
the items var still has to be filled like you did before, and this new mapped updates itself reactively with every change to items.