I want to create an element that the user can create only once.
So far, the best I can think of is to define an element inside an anonymous function and throw an error when I find that the element already exists. Is there a way for him to simply reject creation?
(function(){
var singleton = false;
Polymer({
is:'my-singleton',
created:function(){
if(singleton) {
throw new Error ('only one my-singleton should be created');
}
singleton = this;
}
});
})();
akc42 source
share