Skip to content

Instantly share code, notes, and snippets.

@Polyrhythm
Created April 8, 2014 20:15
Show Gist options
  • Save Polyrhythm/10184363 to your computer and use it in GitHub Desktop.
Save Polyrhythm/10184363 to your computer and use it in GitHub Desktop.
I want callbacks
var vi = new versalInterface();
var Gadget = function() {
var createListeners = function() {
vi.on('attached', this.render());
// I just want to set a general re-render listener when config changes
vi.on('attributesChanged', function(data) {
for (var key in data) {
this.config[key] = data[key];
}
// here I have to special case in the event that I get an image
if (data.asset) {
document.body.innerHTML += /* picture markup */;
}
this.render();
}.bind(this));
}
this.render = function() {
var gadgetHtml = '';
document.body.innerHTML = '';
gadgetHtml = '<button class="upload">upload</button>';
document.body.innerHTML = gadgetHtml;
document.querySelector('upload').addEventListener('click', function(e) {
e.preventDefault();
vi.trigger('requestAsset', { /* ... */ }, /* why can't I put a callback here */);
})
return this;
}
};
@mereskin-zz
Copy link

Because it will be handled by vi.on('attributesChanged', function(){})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment