Closed Yomguithereal closed 8 years ago
@tnrich you might like those methods.
yes please!
+1
This'd be helpful for flux-angular
as angular sometimes has to have mutable data (e.g. ng-model). It'd be great if it was a method on all objects returned by get()
@jrust I just implemented tree/cursor.clone
and tree/cursor.deepClone
this afternoon. This will be part of the upcoming 2.3.0
version.
Thanks @Yomguithereal! I was thinking it'd be most useful if the method was added to whatever object comes back from get()
, similar to how immutable-js adds toJS
to its structures. In my case the store acts like a database and gives out the data to the view-level code that needs it. Some parts of the view-level code may need a certain object to be mutable while others do not. I think I could still use your implementation, but it ends up a little more cumbersome:
var state = new Baobab();
var MyModel = {
getPerson: function(mutable) {
return state[mutable ? 'clone' : 'get]('person'); // idea 1, expose it as an option. doesn't work for getters though
},
getPersonMutable: function() {
return state.clone('person'); // idea 2, as a separate method on the store
}
};
The thing you retrieve from the get
method are raw JavaScript objects and I am confident it would be dangerous to attach arbitrary methods to them. What if you have a key actually named clone
, for instance? In a way, tree/cursor.deepClone
is an equivalent to immutable-js' toJS
.
Yup, good point -- better not to go messing with it.
@jacomyal tmtc