-
-
Save tonylukasavage/8541502 to your computer and use it in GitHub Desktop.
This is essentially what Alloy is doing under the hood for you with backbone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fetch some User | |
var someUser = Alloy.createModel('User', { | |
id: '1234' | |
}); | |
someUser.fetch(); | |
// Create new Profile controller | |
var someProfile = Alloy.createController('Profile', { user: someUser }); | |
// Change model | |
someUser.set('name', 'New Name'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var EVENTS = 'fetch change destroy'; | |
var args = arguments || {}; | |
// remove existing bindings to prevent unexpected behavior and memory leaks | |
$.user.off(EVENTS); | |
// add bindings to new model | |
args.user.on(EVENTS, function() { | |
$.name.text = args.user.get('name'); | |
}); | |
// probably want to delete the bindings on window close | |
$.win.addEventListener('close', function() { | |
args.user.off(EVENTS); | |
}); | |
$.win.open(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Alloy> | |
<Model src="User" id="user" instance="true" /> | |
<Window id="win"> | |
<Label id="name" text="{$.user.name}" /> | |
</Window> | |
</Alloy> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment