arqex / freezer

A tree data structure that emits events on updates, even if the modification is triggered by one of the leaves, making it easier to think in a reactive way.
MIT License
1.28k stars 56 forks source link

Allow to wrap objects in leafs so that they are not manipulated by freezer #82

Closed philippotto closed 8 years ago

philippotto commented 8 years ago

This PR adds the possibility to wrap objects in a "Leaf", which is guaranteed to be not manipulated by freezer. This is useful when handling with native objects or functions which should remain intact and untouched (see #81). Accessing the content of a leaf can be done via a simple get method.

var example = {
    e: Freezer.createLeaf({ func: function() { return true; } })
};
freezer = new Freezer( example );
var unwrappedLeaf = freezer.getData().e.get();
unwrappedLeaf.func() === true;

This change is just a suggestion. I'm happy to discuss a different interface/solution.

arqex commented 8 years ago

Hi @philippotto

Thanks for your PR. Even if I won't accept it, you make freezer to handle instances as leaves by default.

Cheers