-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to get mutable data out of icepick? #7
Comments
You are correct that If you want mutable data back out, they way to get it is to deeply clone the object. You can use something like Lodash Would a |
Having an api would help, I just realize once we freeze an object there is no unfreeze, we can only clone it to a new one. It would seem that If so, perhaps we should just diff the immutable itself, and avoid |
What do you mean by "diff the immutable"? The proper way to see if things have changed would be to see if objects are still reference-equal to their previous values. |
My wording was probably wrong, sorry about that. I simply meant something like If I understand correctly:
True? If so then we shouldn't use TL;DR: |
Yep, I think you understand. If you look at the implementation of |
I have been using icepick in production for a month now and things are working great, though I did find Let say we are using a virtual-dom rendering system that allow template to be rendered both server-side and client-side. Now imagine we are to render a list of tweets. Because data from backend are just normal object, we are doing something like this:
Say we have a variable that's global, but is needed when rendering tweetView:
On server-side this is fine, but on client-side our model is an icepick-powered store, which means At this point we have a few options:
Do you see any better approach? |
Could you do something like: var domain = 'twitter.com';
var tweetViews = tweets.map(function(tweet, i) {
return tweetView(i.assoc(tweet, "domain", domain));
}); The update to the tweet would be discarded, but it would work. The other option would be to update all your tweets with it: var tweets = i.map(tweets, function (tweet) {
return i.assoc(tweet, "domain", domain);
});
// and then
var tweetViews = tweets.map(function(tweet, i) {
return tweetView(tweet);
}); |
One thing I am not sure about: on server-side my |
Yes. It'll work with any plain JS Array or Object, and they don't have to be frozen. |
Wow cheers, would |
Yes, |
There seem to be 2 camp on immutable object:
I believe
icepick
is in the first camp (as opposed toimmutable.js
orseamless-immutable
, which are likely in the 2nd camp).Am I right in thinking
icepick
assume developers will pass its instance directly? Because I see no method to extract mutable data out of it.The text was updated successfully, but these errors were encountered: