diff --git a/src/child/index.js b/src/child/index.js index 525c2914..cd892c01 100644 --- a/src/child/index.js +++ b/src/child/index.js @@ -31,7 +31,9 @@ export type ChildHelpers
= {|
onError : (mixed) => ZalgoPromise ) => void) => void,
getParent : () => CrossDomainWindowType,
- getParentDomain : () => string
+ getParentDomain : () => string,
+ show : () => ZalgoPromise {
onError: (err) => this.onError(err),
onProps: (handler) => this.onProps(handler),
getParent: () => this.parentComponentWindow,
- getParentDomain: () => this.parentDomain
+ getParentDomain: () => this.parentDomain,
+ show: () => this.show(),
+ hide: () => this.hide()
};
}
+ show() : ZalgoPromise , props : (Prop
}
if (typeof prop.childDecorate === 'function') {
- const { close, focus, onError, onProps, resize, getParent, getParentDomain } = helpers;
- return prop.childDecorate({ value, close, focus, onError, onProps, resize, getParent, getParentDomain });
+ const { close, focus, onError, onProps, resize, getParent, getParentDomain, show, hide } = helpers;
+ return prop.childDecorate({ value, close, focus, onError, onProps, resize, getParent, getParentDomain, show, hide });
}
return value;
diff --git a/src/component/props.js b/src/component/props.js
index a7aa44b5..6aebee70 100644
--- a/src/component/props.js
+++ b/src/component/props.js
@@ -184,6 +184,20 @@ export function getBuiltInProps () : BuiltInPropsDefinitionType {
childDecorate: ({ getParentDomain }) => getParentDomain
},
+ show: {
+ type: 'function',
+ required: false,
+ sendToChild: false,
+ childDecorate: ({ show }) => show
+ },
+
+ hide: {
+ type: 'function',
+ required: false,
+ sendToChild: false,
+ childDecorate: ({ hide }) => hide
+ },
+
onDisplay: {
type: 'function',
required: false,
diff --git a/src/parent/drivers.js b/src/parent/drivers.js
index 4df2b85c..09004ea6 100644
--- a/src/parent/drivers.js
+++ b/src/parent/drivers.js
@@ -85,7 +85,9 @@ RENDER_DRIVERS[CONTEXT.IFRAME] = {
'openPrerenderFrame',
'prerender',
'open',
- 'openPrerender'
+ 'openPrerender',
+ 'show',
+ 'hide'
]
};
@@ -124,7 +126,9 @@ if (__ZOID__.__POPUP_SUPPORT__) {
delegate: [
'getProxyContainer',
'renderContainer',
- 'setProxyWin'
+ 'setProxyWin',
+ 'show',
+ 'hide'
]
};
}
diff --git a/src/parent/index.js b/src/parent/index.js
index fd195025..d9e514df 100644
--- a/src/parent/index.js
+++ b/src/parent/index.js
@@ -8,7 +8,7 @@ import { isSameDomain, matchDomain, getDomainFromUrl, isBlankDomain,
import { ZalgoPromise } from 'zalgo-promise/src';
import { addEventListener, uniqueID, elementReady, writeElementToWindow, eventEmitter, type EventEmitterType,
noop, onResize, extendUrl, appendChild, cleanup, type CleanupType, base64encode,
- once, stringifyError, destroyElement, getElementSafe } from 'belter/src';
+ once, stringifyError, destroyElement, getElementSafe, showElement, hideElement } from 'belter/src';
import { ZOID, POST_MESSAGE, CONTEXT, EVENT,
INITIAL_PROPS, WINDOW_REFERENCES } from '../constants';
@@ -42,7 +42,9 @@ export type ParentExportsType = {|
close : () => ZalgoPromise = {|
resize : ({ width : ?number, height : ?number }) => ZalgoPromise => ZalgoPromise {
@@ -91,8 +95,11 @@ export class ParentComponent {
state : StateType
child : ?ChildExportsType
+ proxyContainer : ?ProxyObject , props : PropsInputType ) {
this.initPromise = new ZalgoPromise();
this.handledErrors = [];
@@ -163,7 +170,10 @@ export class ParentComponent {
const openPrerenderFrame = this.openPrerenderFrame();
const renderContainer = ZalgoPromise.hash({ proxyContainer: getProxyContainer, proxyFrame: openFrame, proxyPrerenderFrame: openPrerenderFrame }).then(({ proxyContainer, proxyFrame, proxyPrerenderFrame }) => {
- return this.renderContainer(proxyContainer, { context, uid, proxyFrame, proxyPrerenderFrame });
+ return this.renderContainer(proxyContainer, { context, uid, proxyFrame, proxyPrerenderFrame, visible: this.visible });
+ }).then(proxyContainer => {
+ this.proxyContainer = proxyContainer;
+ return proxyContainer;
});
const open = this.driver.openOnClick
@@ -294,10 +304,32 @@ export class ParentComponent {
focus: () => this.focus(),
resize: ({ width, height }) => this.resize({ width, height }),
onError: (err) => this.onError(err),
- updateProps: (props) => this.updateProps(props)
+ updateProps: (props) => this.updateProps(props),
+ show: () => this.show(),
+ hide: () => this.hide()
};
}
+ show() : ZalgoPromise , isUpdate : boolean = false) {
if (this.component.validate) {
this.component.validate({ props });
@@ -521,10 +553,12 @@ export class ParentComponent {
const close = () => this.close();
const checkClose = () => this.checkClose(win);
const resize = ({ width, height }) => this.resize({ width, height });
+ const show = () => this.show();
+ const hide = () => this.hide();
init.onError = onError;
- return { init, close, checkClose, resize, onError };
+ return { init, close, checkClose, resize, onError, show, hide };
}
resize({ width, height } : { width? : ?number, height? : ?number }) : ZalgoPromise {
});
}
- renderContainer(proxyContainer : ProxyObject {
}).then(({ container, frame, prerenderFrame }) => {
const innerContainer = this.renderTemplate(this.component.containerTemplate, { context, uid, container, frame, prerenderFrame, doc: document });
if (innerContainer) {
+ if (!visible) {
+ hideElement(innerContainer);
+ }
appendChild(container, innerContainer);
this.clean.register(() => destroyElement(innerContainer));
+ this.proxyContainer = getProxyObject(innerContainer);
return getProxyObject(innerContainer);
}
});