Last active
March 12, 2020 22:31
-
-
Save worldoptimizer/3b581623cd27969e90d4996f0b69b1bc to your computer and use it in GitHub Desktop.
A simple example for an extended symbol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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