Skip to content

Instantly share code, notes, and snippets.

@unscriptable
Created November 23, 2011 11:05
Show Gist options
  • Save unscriptable/1388442 to your computer and use it in GitHub Desktop.
Save unscriptable/1388442 to your computer and use it in GitHub Desktop.
cujo-ish view/widget
//MyView.js (filename above is just to sort this to top)
define([
'wire!./myView/spec',
'poly!poly/array' // for instance, not used in this example
],
function (spec) {
return spec;
});
// myView/controller.js
define({
_onClick: function (e) {
this.rootNode.classList.toggle(this.states.selected);
}
});
define({
plugins: [
{ module: 'wire/dom' },
{ module: 'wire/html5Event' } // adds `on` facet plus html5's node.classList!
],
oocssStates: {
selected: 'selected'
},
controller: {
module: './myView/controller',
on: {
rootNode: 'click:_onClick'
},
properties: {
states: { $ref: 'oocssStates' }
}
},
template: { module: 'text!./myView/template' },
strings: { module: 'i18n!./myView/strings' }
});
// myView/strings.js
define({
greeting: 'Hello, cujo-er!'
});
<!- myView/template.html -->
<div class="myview" data-cujo-bind="rootNode"><!-- should rootNode be implicit? -->
<p>${strings.greeting}</p>
<p data-cujo-bind="foo"></p>
</div>
// MyView.js when concatenated together using cram.js
// cram.js needs two new features to make this work:
// 1. an option to NOT normalize module ids
// 2. an option to more easily exclude modules from the build (wire plugins, for instance)
define('./myView/controller', {
_onClick: function (e) {
this.rootNode.classList.toggle(this.states.selected);
}
});
define('text!.myView/template.html', function () {
return '<div class="myview" data-cujo-bind="rootNode"><!-- should rootNode be implicit? -->\n\t<p>${strings.greeting}</p>\n\t<p data-cujo-bind="foo"></p>\n</div>';
});
define('i18n!./myView/strings', {
greeting: 'Hello, cujo-er!'
});
define('wire!./myView/spec', {
plugins: [
{ module: 'wire/dom' },
{ module: 'wire/html5Event' } // adds `on` facet plus html5's node.classList!
],
oocssStates: {
selected: 'selected'
},
controller: {
module: './myView/controller',
on: {
rootNode: 'click:_onClick'
},
properties: {
states: { $ref: 'oocssStates' }
}
},
template: { module: 'text!./myView/template' },
strings: { module: 'i18n!./myView/strings' }
});
define(/* yes, this should stay anonymous! */ [
'wire!./myView/spec',
'poly!poly/array' // for instance, not used in this example
],
function (spec) {
return spec;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment