Skip to content

Instantly share code, notes, and snippets.

@worldoptimizer
Last active March 12, 2020 22:31
Show Gist options
  • Save worldoptimizer/3b581623cd27969e90d4996f0b69b1bc to your computer and use it in GitHub Desktop.
Save worldoptimizer/3b581623cd27969e90d4996f0b69b1bc to your computer and use it in GitHub Desktop.
A simple example for an extended symbol
function symbolInit (hypeDocument, element, event){
console.log('HypeSymbolInit');
var symbolInstance = hypeDocument.getSymbolInstanceForElement(element);
var symbolElement = symbolInstance.element();
switch (symbolInstance.symbolName()){
case 'counter':
Object.assign( symbolInstance, {
_counter: 0,
increase: function(){
this._counter++;
this.refresh();
},
decrease: function(){
this._counter--;
this.refresh();
},
getValue: function(){
return this._counter;
},
refresh: function(){
symbolElement.querySelector('.display').innerHTML = this._counter;
},
});
symbolElement.querySelector('.upBtn').onclick = function(){
symbolInstance.increase();
}
symbolElement.querySelector('.downBtn').onclick = function(){
symbolInstance.decrease();
}
symbolInstance.refresh();
break;
}
}
function symbolLoad (hypeDocument, element, event){
var symbolInstance = hypeDocument.getSymbolInstanceForElement(element);
switch (symbolInstance.symbolName()){
case 'counter':
symbolInstance.refresh();
break;
}
}
window.HYPE_eventListeners.push({"type":"HypeSymbolInit", "callback":symbolInit});
window.HYPE_eventListeners.push({"type":"HypeSymbolLoad", "callback":symbolLoad});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment