{ "id": "114978", "key": "ALOY-672", "fields": { "issuetype": { "id": "4", "description": "An improvement or enhancement to an existing feature or task.", "name": "Improvement", "subtask": false }, "project": { "id": "11113", "key": "ALOY", "name": "Alloy", "projectCategory": { "id": "10400", "description": "Tools for developing applications", "name": "Tooling" } }, "fixVersions": [], "resolution": { "id": "3", "description": "The problem is a duplicate of an existing issue.", "name": "Duplicate" }, "resolutiondate": "2014-01-21T15:16:21.000+0000", "created": "2013-05-27T10:53:44.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [ "alloy", "model", "view" ], "versions": [], "issuelinks": [], "assignee": null, "updated": "2018-03-07T22:25:42.000+0000", "status": { "description": "A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.", "name": "Resolved", "id": "5", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "13605", "name": "Models" }, { "id": "12329", "name": "Runtime", "description": "Generic bucket for uncategorized runtime issues" } ], "description": "Make it possible to bind an existing Model instance to a Model element in Alloy. \r\n\r\nCurrently it is possible to copy the attributes into the Model element, but we do not get data binding on the original Model instance.\r\n\r\nSee: https://gist.github.com/timanrebel/5643468\r\n\r\n", "attachment": [], "flagged": false, "summary": "Alloy for binding existing Model instances to Model element", "creator": { "name": "timanrebel", "key": "timanrebel", "displayName": "Timan Rebel", "active": true, "timeZone": "Europe/London" }, "subtasks": [], "reporter": { "name": "timanrebel", "key": "timanrebel", "displayName": "Timan Rebel", "active": true, "timeZone": "Europe/London" }, "environment": null, "comment": { "comments": [ { "id": "254088", "author": { "name": "fokkezb", "key": "fokke", "displayName": "Fokke Zandbergen", "active": true, "timeZone": "Europe/Amsterdam" }, "body": "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.\r\n\r\nh1. Single instance (singleton)\r\nOne solution is to use {{Alloy.Models.instance}}, which works fine and is explained on:\r\nhttp://fokkezb.nl/2013/05/27/bind-existing-model/\r\n\r\nBut this only works for a single concurrent instance per model, since it will take it's name from the name of the model.\r\n\r\nh1. Multiple concurrent instances\r\nTo be able to use multiple concurrent instance I see 2 solutions:\r\n\r\nh2. A) Custom global instance\r\nWe could specify a custom global instance using the existing {{src}} attribute:\r\n\r\n{code}\r\n\r\n{code}\r\n\r\nWhich by use of '.' in {{src}} would trigger Alloy to compile into:\r\n\r\n{code}\r\n$.myBook = Alloy.Globals.books.someBook;\r\n{code}\r\n\r\nh2. B) Local instance from singleton collection\r\n\r\nAnother way could be to load a model from a existing collection singleton:\r\n\r\n{code}\r\n\r\n{code}\r\n\r\nWhich by having another value then {{true}} (and no {{.}} like solution A) would compile to:\r\n\r\n{code}\r\n$.myBook = Alloy.Collections.instance(\"book\").book.get(\"123\");\r\n{code}\r\n\r\nBoth A) en B) could be implemented at the same time.", "updateAuthor": { "name": "fokkezb", "key": "fokke", "displayName": "Fokke Zandbergen", "active": true, "timeZone": "Europe/Amsterdam" }, "created": "2013-05-27T14:22:07.000+0000", "updated": "2013-05-27T14:22:49.000+0000" }, { "id": "288895", "author": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "[~timanrebel] you have the following in your gist:\n\n{code:javascript}\n/**\n * Does not work\n */\n// $.user = args.user;\n{code}\n\nPlease elaborate. What actually happens when you try the direct assignment?", "updateAuthor": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2014-01-20T22:15:08.000+0000", "updated": "2014-01-20T22:15:08.000+0000" }, { "id": "288995", "author": { "name": "timanrebel", "key": "timanrebel", "displayName": "Timan Rebel", "active": true, "timeZone": "Europe/London" }, "body": "It overwrites the model created by Alloy, including its bindings and nothing happens", "updateAuthor": { "name": "timanrebel", "key": "timanrebel", "displayName": "Timan Rebel", "active": true, "timeZone": "Europe/London" }, "created": "2014-01-21T08:14:34.000+0000", "updated": "2014-01-21T08:14:34.000+0000" }, { "id": "289021", "author": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "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:\r\n\r\nhttps://gist.github.com/tonylukasavage/8541502", "updateAuthor": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2014-01-21T15:16:21.000+0000", "updated": "2014-01-21T15:16:21.000+0000" } ], "maxResults": 4, "total": 4, "startAt": 0 } } }