Created
January 22, 2012 02:28
-
-
Save pieterv/1655127 to your computer and use it in GitHub Desktop.
Example best practice wire spec
This file contains 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
define( { | |
plugins: [ | |
{ module: 'wire/jquery/dom' }, | |
// Responsible for `dom.query.context!` | |
// This would make dom queries in the context of the current view | |
// You would delegate out to backbones `view.$()` function for this | |
// (http://backbonejs.org/#View-dollar) | |
// A better plugin name could be thought up, maybe `view.query` dunno | |
{ module: 'wire/backbone/query' }, | |
// Responsiable for the `connect` or maybe the `dom` facets | |
// A basic version of this has already been created (https://github.com/pieter-vanderwerff/todomvc/blob/master/dependency-examples/backbone_curl_wire/js/src/libs/wire/wire/backbone/events.js) | |
{ module: 'wire/backbone/events' } | |
], | |
view: { | |
create: { | |
module: 'view/app', | |
args: [ | |
// Constructor options | |
{ | |
// Get the view holder using a standard dom.query plugin | |
el: { $ref: 'dom.query!#App', i:0 } | |
} | |
] | |
}, | |
properties: { | |
// A context based dom query, this would be the same as | |
// `dom.query!#App .button` | |
button: { $ref: 'dom.query.context!.button', i:0 } | |
}, | |
// Dom binding option 1 | |
// This implementation would be very similar to the way you do dom event binding | |
// in backbone currently but would make the plugin less interchangeable with | |
// other libraries (http://backbonejs.org/#View-delegateEvents) | |
events: { // or other more relevant key word | |
'event_name #Element.selector': 'currentModuleFunction' | |
}, | |
connect: { | |
// Dom binding option 2 | |
// This would more closely resemble how the current dojo/events plugin works but | |
// because the backbone.delagateEvents function takes a string not a Dom element | |
// the dom.query.context plugin wouldn't do anything in this context (which would require | |
// it to understand its context or be overridden in this context ) | |
'dom.query.context!.selector': { | |
'event_name': 'currentModuleFunction' | |
}, | |
// My current backbone/events plugin supports this functionality already | |
// It delegates to `backboneModule.bind( 'event_name', currentModuleFunction )` internally | |
// This only works with objects that extend the backbone.events object | |
model: { | |
'change': 'render' | |
} | |
} | |
}, | |
model: { | |
create: 'model/app' | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment