Collection discrepancy


Hi, I’ve got 2 collections with Sync persistence. Both of them have the same ID. I When I add a model through JS one of them updates while the other one does not… any thoughts?

JS as follows:

var myCol = Noodl.Collection.get("Messages");
        Text: "placeholder text",
        User: 1


It doesn’t seem that Model’s created with JS persist in the collection also, after a ‘refresh’/reload of the window they’re gone.


And just to describe the process of getting into this state.
I created a collection “Messages”, then followed a ‘noodl’ way of adding models to it (similar to the collection tutorial). Later decided that I need a JS way to do so, with the code above.

When I create a new collection “Messages” it adds models from JS but doesn’t sync with the collection that was created earlier.


Unfortunately the persist features aren’t available in Javascript. The best you can do is to combine a JS node with a Model node, and try to control the model node with the JS node. I.e. sending model id, values, and a store signal from JS to a Model node.


Thanks! I’ll give it a go.

I think my issue comes from a misunderstanding of how Noodl handles a collections/models behind the curtains. I saw it as a ‘data-base’ of some sorts which is ‘there’ on load. Whereas I think the data gets loaded into a collection on loading Noodl, meaning the data doesn’t live in it, per-se, but is populated on opening the project? Or am I misunderstanding this? I think I lost my point…

having a:

myCollection.on('add',function(args) {

on Noodl project start-up calls this function (something I didn’t expect to happen).


Ah, I see what you mean. If you enable persist, it’ll basically store the data to disk when you use the “persist” input, and load it from disk when you do “fetch”. Except if you pick sync, then you don’t need to do anything, it’ll automatically load the data and persist it for you whenever it changes.

So yes, the models and collections are recreated, so the ‘add’ signals etc are always called.


A follow up question to this:

I’m trying to create a similar project to the ‘Collections’ tutorial but my collection is populated not through a slider (like in the tutorial) but with a REST call that returns 10 objects. Which I’m adding as ‘models’ to that collection (through the same REST node)

My question is - how do I sync that collection across different NOODL prototype sections? Since it seems that the collection data doesn’t persist.

Let’s say my call returns 15 objects which I want to create a collection out of. I perform this call every 10 seconds or so. Right now I don’t have any way to compare the returned the 15 objects to the previously received one’s so I’m clearing the collection and populating it over and over. But after the 1st call the ‘sync’ing’ of the collection seems to stop? I am still making the REST requests but the collection is not updating inside the ‘for each item’ part of the prototype. Again, this is if I’m trying to create a similar project to the ‘collections’ tutorial.