From 2a17108857bba66bcd5dc55e4e2ddce4cba35ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Mon, 3 Feb 2020 19:15:01 -0500 Subject: [PATCH 1/3] add setDecorator for wrapper components --- @plotly/dash-component-plugins/package.json | 2 +- @plotly/dash-component-plugins/src/dynamicImport.js | 10 +++++++++- @plotly/dash-component-plugins/src/index.js | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/@plotly/dash-component-plugins/package.json b/@plotly/dash-component-plugins/package.json index 0d51938be5..eaf967ced9 100644 --- a/@plotly/dash-component-plugins/package.json +++ b/@plotly/dash-component-plugins/package.json @@ -1,6 +1,6 @@ { "name": "@plotly/dash-component-plugins", - "version": "1.1.0", + "version": "1.2.0", "description": "Plugins for Dash Components", "repository": { "type": "git", diff --git a/@plotly/dash-component-plugins/src/dynamicImport.js b/@plotly/dash-component-plugins/src/dynamicImport.js index 29530bc9cf..3d8be31fe6 100644 --- a/@plotly/dash-component-plugins/src/dynamicImport.js +++ b/@plotly/dash-component-plugins/src/dynamicImport.js @@ -1,5 +1,7 @@ import { lazy } from 'react'; +const isLazyProp = '_dashprivate_isLazyComponentReady'; + export const asyncDecorator = (target, promise) => { let resolve; const isReady = new Promise(r => { @@ -20,12 +22,18 @@ export const asyncDecorator = (target, promise) => { }), }; - Object.defineProperty(target, '_dashprivate_isLazyComponentReady', { + Object.defineProperty(target, isLazyProp, { get: () => state.isReady }); return state.get; }; +export const setDecorator = (target, source) => { + Object.defineProperty(target, isLazyProp, { + get: () => isReady(source) + }); +} + export const isReady = target => target && target._dashprivate_isLazyComponentReady; diff --git a/@plotly/dash-component-plugins/src/index.js b/@plotly/dash-component-plugins/src/index.js index 4cff6b60a1..25a025e350 100644 --- a/@plotly/dash-component-plugins/src/index.js +++ b/@plotly/dash-component-plugins/src/index.js @@ -1,5 +1,5 @@ -import { asyncDecorator, isReady } from './dynamicImport'; +import { asyncDecorator, isReady, setDecorator } from './dynamicImport'; import History from './History'; -export { asyncDecorator, isReady }; +export { asyncDecorator, isReady, setDecorator }; export { History }; \ No newline at end of file From 142986c3665c458f99f8b3749f7b7b973f73d396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Mon, 3 Feb 2020 19:16:31 -0500 Subject: [PATCH 2/3] revert --- @plotly/dash-component-plugins/src/dynamicImport.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/@plotly/dash-component-plugins/src/dynamicImport.js b/@plotly/dash-component-plugins/src/dynamicImport.js index 3d8be31fe6..ca8b4407ce 100644 --- a/@plotly/dash-component-plugins/src/dynamicImport.js +++ b/@plotly/dash-component-plugins/src/dynamicImport.js @@ -1,7 +1,5 @@ import { lazy } from 'react'; -const isLazyProp = '_dashprivate_isLazyComponentReady'; - export const asyncDecorator = (target, promise) => { let resolve; const isReady = new Promise(r => { @@ -22,7 +20,7 @@ export const asyncDecorator = (target, promise) => { }), }; - Object.defineProperty(target, isLazyProp, { + Object.defineProperty(target, '_dashprivate_isLazyComponentReady', { get: () => state.isReady }); @@ -30,7 +28,7 @@ export const asyncDecorator = (target, promise) => { }; export const setDecorator = (target, source) => { - Object.defineProperty(target, isLazyProp, { + Object.defineProperty(target, '_dashprivate_isLazyComponentReady', { get: () => isReady(source) }); } From ddf7bb42206eb5dca1008bae23cd2994f62ca509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Mon, 3 Feb 2020 19:54:03 -0500 Subject: [PATCH 3/3] rename setDecorator to inheritAsyncDecorator --- @plotly/dash-component-plugins/src/dynamicImport.js | 2 +- @plotly/dash-component-plugins/src/index.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/@plotly/dash-component-plugins/src/dynamicImport.js b/@plotly/dash-component-plugins/src/dynamicImport.js index ca8b4407ce..c4ed18b121 100644 --- a/@plotly/dash-component-plugins/src/dynamicImport.js +++ b/@plotly/dash-component-plugins/src/dynamicImport.js @@ -27,7 +27,7 @@ export const asyncDecorator = (target, promise) => { return state.get; }; -export const setDecorator = (target, source) => { +export const inheritAsyncDecorator = (target, source) => { Object.defineProperty(target, '_dashprivate_isLazyComponentReady', { get: () => isReady(source) }); diff --git a/@plotly/dash-component-plugins/src/index.js b/@plotly/dash-component-plugins/src/index.js index 25a025e350..3448f9e7b8 100644 --- a/@plotly/dash-component-plugins/src/index.js +++ b/@plotly/dash-component-plugins/src/index.js @@ -1,5 +1,5 @@ -import { asyncDecorator, isReady, setDecorator } from './dynamicImport'; +import { asyncDecorator, inheritAsyncDecorator, isReady } from './dynamicImport'; import History from './History'; -export { asyncDecorator, isReady, setDecorator }; +export { asyncDecorator, inheritAsyncDecorator, isReady }; export { History }; \ No newline at end of file