[ALOY-672] Alloy for binding existing Model instances to Model element
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Medium |
Status | Resolved |
Resolution | Duplicate |
Resolution Date | 2014-01-21T15:16:21.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Models, Runtime |
Labels | alloy, model, view |
Reporter | Timan Rebel |
Assignee | Unknown |
Created | 2013-05-27T10:53:44.000+0000 |
Updated | 2018-03-07T22:25:42.000+0000 |
Description
Make it possible to bind an existing Model instance to a Model element in Alloy.
Currently it is possible to copy the attributes into the Model element, but we do not get data binding on the original Model instance.
See: https://gist.github.com/timanrebel/5643468
In order to use an existing model instance, we need to be able to refer to some existing object in memory or load one from a persistant storage.
Single instance (singleton)
One solution is to useAlloy.Models.instance
, which works fine and is explained on: http://fokkezb.nl/2013/05/27/bind-existing-model/ But this only works for a single concurrent instance per model, since it will take it's name from the name of the model.Multiple concurrent instances
To be able to use multiple concurrent instance I see 2 solutions:A) Custom global instance
We could specify a custom global instance using the existingsrc
attribute:Which by use of '.' in
src
would trigger Alloy to compile into:B) Local instance from singleton collection
Another way could be to load a model from a existing collection singleton:Which by having another value then
true
(and no.
like solution A) would compile to:Both A) en B) could be implemented at the same time.
[~timanrebel] you have the following in your gist:
Please elaborate. What actually happens when you try the direct assignment?
It overwrites the model created by Alloy, including its bindings and nothing happens
This will eventually be resolved a bit more robustly with a programmatic binding API (ALOY-931). In the meantime though, you can do this with straight Backbone calls. I forked your gist and modified it to do so (untested). Even if it needs tweaking, though, it should show you how you can achieve your goal of dynamically changing the binding: https://gist.github.com/tonylukasavage/8541502