From 3f189c2f3f1cebdc0cf3c71a506b3614e51dc8bd Mon Sep 17 00:00:00 2001 From: Konstantinos Kataras Date: Mon, 26 Aug 2019 08:49:27 +0300 Subject: [PATCH 1/2] Call handler accepts dynamic imports --- .gitignore | 1 + jsb.js | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 .gitignore 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..36c4584 100644 --- a/jsb.js +++ b/jsb.js @@ -324,10 +324,29 @@ 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 handles the various cases of different handler types class or simple function + * (the second type is for handling dynamic imports) + * + * @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); + } + }); } }, From a121d819632a2aaa8d0fcbaf577eeb907fd840b6 Mon Sep 17 00:00:00 2001 From: Konstantinos Kataras Date: Mon, 26 Aug 2019 09:12:58 +0300 Subject: [PATCH 2/2] Comment updated. --- jsb.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jsb.js b/jsb.js index 36c4584..a92afff 100644 --- a/jsb.js +++ b/jsb.js @@ -328,8 +328,9 @@ }, /** - * This function handles the various cases of different handler types class or simple function - * (the second type is for handling dynamic imports) + * 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