howech/gestalt

"Proxy" mode for attaching objects

Closed this issue · 4 comments

Just as you can attach objects to each other with methods like "addAsDefault", it would be super useful if there were a way to attach Object A to Object B such that B then proxied A and writes to B's properties which were proxied from A would write to A's properties too. Writes to B's properties which were not originally placed there by Proxying A would have no affect on A. Getting properties from B could function just though A were added as a default.

Above where I say Object I mean Gestalt configuration object.

Would it be sufficient to have an update("name","value","source") method that lives on the ConfigContainer object?

The set("name","value","source") method on ConfigContainer normally just operates on the default layer config object. An update would look for the first priority config object in the stack that actually holds a value for "name", and then calls set on that object.

over = new gestalt.Configuration();
middle = new gestalt.ConfigContainer();
under = new gestalt.Configuration();

middle.setOverride( over );
middle.setDefault( under );

under.set("a","under");
under.set("b","under");
over.set("b","over");
middle.set("c","middle");

middle.update("a","update");
middle.update("b","update");
middle.update("c","update");
middle.update("d","update");

// results:
// over containes b -> "update"
// under contains a -> "update", b-> "under"
// middle's default layer contains c->"update, d->"update"

That would totally work even better than my suggestion.

Update functionality added. Decided that the semantics of the source are a little different than for set: update does not use the object default source.