Skip to content

Instantly share code, notes, and snippets.

@ericf
Created January 3, 2012 23:54
Show Gist options
  • Select an option

  • Save ericf/1557651 to your computer and use it in GitHub Desktop.

Select an option

Save ericf/1557651 to your computer and use it in GitHub Desktop.
// Creates a Person model which has a `name` attribute.
Y.Person = Y.Base.create('person', Y.Model, [], {}, {
ATTRS: {
name: {}
}
});
// Creates a HelloView which can say hello to a Person, or to the World if a
// Person model is not specified.
Y.HelloView = Y.Base.create('helloView', Y.View, [], {
render: function () {
var person = this.get('model'),
name = person && person.get('name');
this.get('container').set('text', 'Hello ' + (name || 'World') + '!');
return this;
}
});
// Creates a new App instance and registers the HelloView.
var app = new Y.App({
views: {
hello: {type: 'HelloView'}
}
});
// Adds a route handler for "/" to show the HelloView.
app.route('/', function (req) {
this.showView('hello');
});
// Adds a route handler for "/:name" to show the HelloView with a Person model.
app.route('/:name', function (req) {
this.showView('hello', {
model: new Y.Person(req.params)
});
});
// Renders the app, then saves a new history entry for "/ericf" which will
// dispatch the "/:name" route handler.
app.render().save('/ericf');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment