Skip to content

Instantly share code, notes, and snippets.

@thehydroimpulse
Created April 8, 2014 23:59
Show Gist options
  • Save thehydroimpulse/10210946 to your computer and use it in GitHub Desktop.
Save thehydroimpulse/10210946 to your computer and use it in GitHub Desktop.
// actionbutton/index.js
var template = require('./template.html');
var View = require('view');
var NextView = require('next-view');
var SpinnerAnimation = require('spinner-animation');
var resource = require('resource');
var animation = require('animation');
var ActionButton = View.create()
.use(View.compiler(template))
.use(animation())
.scope(function(scope) {
scope.records = [];
});
// Button is pressed.
ActionButton.prototype.click = function(event) {
var self = this;
// Initialize a new animation:
this.animation('loading', new Spinner()).begin();
// Load a resource (ajax)
resource('name').all(function(err, records) {
// Stop the animation:
self.animation('loading').stop();
// Update the scope:
self.scope.swap('records', records);
// Mount the next component.
self.component('next', new NextView()).mount();
});
};
// actionbutton/template.html
<button class="ui button" data-click="click">
ActionButton
</button>
<span data-animation="loading"></span>
<span data-component="next"></span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment