diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/jsb.js b/jsb.js index 6921083..a92afff 100644 --- a/jsb.js +++ b/jsb.js @@ -324,10 +324,30 @@ value_string = dom_element.getAttribute('data-jsb'); } - if (value_string !== null) { - new this.handlers[key](dom_element, this.parseValueString(value_string)); - } else { - new this.handlers[key](dom_element); + this.handleJsbHandlers(this.handlers[key], dom_element, value_string); + }, + + /** + * This function creates an object from the handler constructor function and in the case + * where that function is not the handler but a dynamic import it uses the promise + * resolver to get the handler from the promise and instantiate the behaviour. + * + * @param jsb_handler + * @param dom_element + * @param value_string + */ + handleJsbHandlers: function(jsb_handler, dom_element, value_string) { + var options = value_string !== null ? this.parseValueString(value_string): undefined; + var result = new jsb_handler(dom_element, options); + + if (typeof result.then === 'function') { + result.then(object => { + try { + new object.default(dom_element, options); + } catch (error) { + console.error(error); + } + }); } },