Skip to content

Instantly share code, notes, and snippets.

@danwrong
Created July 31, 2013 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danwrong/6124263 to your computer and use it in GitHub Desktop.
Save danwrong/6124263 to your computer and use it in GitHub Desktop.
Just a really rough sketch of what I'd like to see as a data binding layer for flight. The idea is that its all just components and events but the model like behavior, the data binding and the rendering are all just added via mixins....
// Model
var Todo = defineComponent(asModel, function() {
// this would just be a normal component with extra methods
// that define bindable attributes and other logic
this.properties({
text: String,
complete: Boolean
});
this.after('initialize', function() {
// listen to other events do any app specific initialization
});
});
// UI Component
var TodoItem = defineComponent(function() {
// addtl logic here
}, withTemplate('todo.mustache'), withDataBinding);
// Then attach the components
Todo.attachTo(document, { url: '/todo.json' });
TodoList.attachTo( 'div.todos', { collection: Todo });
// Under the hood the model mixin are basically just firing predictably named events on property changes,
// something like 'todo.changed.text' and the data binding mixin is handling these automatically and then
// working out when to call the render method which would be part of the withTemplate mixin.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment