So I made a workaround for collections that I think works pretty well using a third party collections library. Although it lead me to think that we may run into difficulties when inflating a View on the client that is heavily dependent on third party stuff and not on fruitmachine core.
Solution
New hooks via the event model can help us here. When a view is using a collection it will probably be stored like myview.collection. When we call myview.toJSON() to send down to the client with the html, what happens to myview.collection? It gets lost!
But if we fire a new event 'tojson' we can ensure that extra data can be bolted on as and when needed.
We would also need a second event that would be fired on the client 'inflation'. That would fire on each view when it is inflated from the server.
myview.on('inflation', function(options) {
// ... do something with options.collection
});
What does this all enable?
This basically empowers FruitMachine helpers to interviene at every stage from server to client. Getting involved in the toJSON() and 'inflation' events. My collection example could then become a helper, seeing that collections safely arrive on the client.
So I made a workaround for collections that I think works pretty well using a third party collections library. Although it lead me to think that we may run into difficulties when inflating a View on the client that is heavily dependent on third party stuff and not on fruitmachine core.
Solution
New hooks via the event model can help us here. When a view is using a collection it will probably be stored like
myview.collection
. When we callmyview.toJSON()
to send down to the client with the html, what happens tomyview.collection
? It gets lost!But if we fire a new event
'tojson'
we can ensure that extra data can be bolted on as and when needed.We would also need a second event that would be fired on the client
'inflation'
. That would fire on each view when it is inflated from the server.What does this all enable?
This basically empowers FruitMachine helpers to interviene at every stage from server to client. Getting involved in the
toJSON()
and 'inflation' events. My collection example could then become a helper, seeing that collections safely arrive on the client.