diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-11-08 15:07:07 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-11-08 15:19:39 +0100 |
commit | afb9fba64be1f15a3ce3ed31214a704e73e5e8bb (patch) | |
tree | 6f69712a8c976178c05144483ff0c8e9b09445c8 /thirdparty/preact/src | |
parent | b37e7762bb5492cbd6788863232e7d2634ab5e5c (diff) | |
parent | 6e5fb04d3f3f9a6cd43ac20896d73321dd079f96 (diff) | |
download | wallet-core-afb9fba64be1f15a3ce3ed31214a704e73e5e8bb.tar.xz |
Update preact version
Diffstat (limited to 'thirdparty/preact/src')
-rw-r--r-- | thirdparty/preact/src/dom/index.js | 9 | ||||
-rw-r--r-- | thirdparty/preact/src/h.js | 9 | ||||
-rw-r--r-- | thirdparty/preact/src/linked-state.js | 24 | ||||
-rw-r--r-- | thirdparty/preact/src/options.js | 9 | ||||
-rw-r--r-- | thirdparty/preact/src/preact.d.ts | 21 | ||||
-rw-r--r-- | thirdparty/preact/src/vdom/component.js | 27 | ||||
-rw-r--r-- | thirdparty/preact/src/vdom/diff.js | 25 | ||||
-rw-r--r-- | thirdparty/preact/src/vdom/index.js | 7 |
8 files changed, 81 insertions, 50 deletions
diff --git a/thirdparty/preact/src/dom/index.js b/thirdparty/preact/src/dom/index.js index 248a3cdc5..b72d056af 100644 --- a/thirdparty/preact/src/dom/index.js +++ b/thirdparty/preact/src/dom/index.js @@ -1,4 +1,4 @@ -import { ATTR_KEY, NON_DIMENSION_PROPS, NON_BUBBLING_EVENTS } from '../constants'; +import { NON_DIMENSION_PROPS, NON_BUBBLING_EVENTS } from '../constants'; import options from '../options'; import { toLowerCase, isString, isFunction, hashToClassName } from '../util'; @@ -20,8 +20,7 @@ export function removeNode(node) { * @param {any} previousValue The last value that was set for this name/node pair * @private */ -export function setAccessor(node, name, value, old, isSvg) { - node[ATTR_KEY][name] = value; +export function setAccessor(node, name, old, value, isSvg) { if (name==='className') name = 'class'; @@ -29,8 +28,8 @@ export function setAccessor(node, name, value, old, isSvg) { value = hashToClassName(value); } - if (name==='key' || name==='children' || name==='innerHTML') { - // skip these + if (name==='key') { + // ignore } else if (name==='class' && !isSvg) { node.className = value || ''; diff --git a/thirdparty/preact/src/h.js b/thirdparty/preact/src/h.js index e57ce4bde..c137bec84 100644 --- a/thirdparty/preact/src/h.js +++ b/thirdparty/preact/src/h.js @@ -2,8 +2,7 @@ import { VNode } from './vnode'; import options from './options'; -let stack = []; - +const stack = []; /** JSX/hyperscript reviver @@ -16,7 +15,8 @@ let stack = []; * render(<span>foo</span>, document.body); */ export function h(nodeName, attributes) { - let children, lastSimple, child, simple, i; + let children = [], + lastSimple, child, simple, i; for (i=arguments.length; i-- > 2; ) { stack.push(arguments[i]); } @@ -35,8 +35,7 @@ export function h(nodeName, attributes) { children[children.length-1] += child; } else { - if (children) children.push(child); - else children = [child]; + children.push(child); lastSimple = simple; } } diff --git a/thirdparty/preact/src/linked-state.js b/thirdparty/preact/src/linked-state.js index ed72bd8bc..b6959df73 100644 --- a/thirdparty/preact/src/linked-state.js +++ b/thirdparty/preact/src/linked-state.js @@ -8,21 +8,17 @@ import { isString, delve } from './util'; * @private */ export function createLinkedState(component, key, eventPath) { - let path = key.split('.'), - p0 = path[0]; + let path = key.split('.'); return function(e) { - let t = e && e.currentTarget || this, - s = component.state, - obj = s, - v = isString(eventPath) ? delve(e, eventPath) : t.nodeName ? ((t.nodeName+t.type).match(/^input(che|rad)/i) ? t.checked : t.value) : e, - i; - if (path.length>1) { - for (i=0; i<path.length-1; i++) { - obj = obj[path[i]] || (obj[path[i]] = {}); - } - obj[path[i]] = v; - v = s[p0]; + let t = e && e.target || this, + state = {}, + obj = state, + v = isString(eventPath) ? delve(e, eventPath) : t.nodeName ? (t.type.match(/^che|rad/) ? t.checked : t.value) : e, + i = 0; + for ( ; i<path.length-1; i++) { + obj = obj[path[i]] || (obj[path[i]] = !i && component.state[path[i]] || {}); } - component.setState({ [p0]: v }); + obj[path[i]] = v; + component.setState(state); }; } diff --git a/thirdparty/preact/src/options.js b/thirdparty/preact/src/options.js index 35b7418fc..49869604e 100644 --- a/thirdparty/preact/src/options.js +++ b/thirdparty/preact/src/options.js @@ -15,4 +15,13 @@ export default { * @param {VNode} vnode A newly-created VNode to normalize/process */ //vnode(vnode) { } + + /** Hook invoked after a component is mounted. */ + // afterMount(component) { } + + /** Hook invoked after the DOM is updated with a component's latest render. */ + // afterUpdate(component) { } + + /** Hook invoked immediately before a component is unmounted. */ + // beforeUnmount(component) { } }; diff --git a/thirdparty/preact/src/preact.d.ts b/thirdparty/preact/src/preact.d.ts index 2dd8299a9..784844152 100644 --- a/thirdparty/preact/src/preact.d.ts +++ b/thirdparty/preact/src/preact.d.ts @@ -4,8 +4,14 @@ declare namespace preact { key?:string; } + interface DangerouslySetInnerHTML { + __html: string; + } + interface PreactHTMLAttributes { + dangerouslySetInnerHTML?:DangerouslySetInnerHTML; key?:string; + ref?:(el?: Element) => void; } interface VNode { @@ -51,8 +57,8 @@ declare namespace preact { abstract render(props:PropsType & ComponentProps, state:any):JSX.Element; } - function h<PropsType>(node:ComponentConstructor<PropsType, any>, params:PropsType, ...children:(JSX.Element|string)[]):JSX.Element; - function h(node:string, params:JSX.HTMLAttributes&JSX.SVGAttributes, ...children:(JSX.Element|string)[]):JSX.Element; + function h<PropsType>(node:ComponentConstructor<PropsType, any>, params:PropsType, ...children:(JSX.Element|JSX.Element[]|string)[]):JSX.Element; + function h(node:string, params:JSX.HTMLAttributes&JSX.SVGAttributes&{[propName: string]: any}, ...children:(JSX.Element|JSX.Element[]|string)[]):JSX.Element; function render(node:JSX.Element, parent:Element, merge?:boolean):Element; @@ -72,6 +78,11 @@ declare module "preact" { export = preact; } +declare module "preact/devtools" { + // Empty. This module initializes the React Developer Tools integration + // when imported. +} + declare namespace JSX { interface Element extends preact.VNode { @@ -277,8 +288,8 @@ declare namespace JSX { charSet?:string; challenge?:string; checked?:boolean; - class?:string; - className?:string; + class?:string | { [key:string]: boolean }; + className?:string | { [key:string]: boolean }; cols?:number; colSpan?:number; content?:string; @@ -551,4 +562,4 @@ declare namespace JSX { tspan:SVGAttributes; use:SVGAttributes; } -} +}
\ No newline at end of file diff --git a/thirdparty/preact/src/vdom/component.js b/thirdparty/preact/src/vdom/component.js index bb2e4fa5d..64e7ff81f 100644 --- a/thirdparty/preact/src/vdom/component.js +++ b/thirdparty/preact/src/vdom/component.js @@ -154,11 +154,11 @@ export function renderComponent(component, opts, mountAll, isChild) { let baseParent = initialBase.parentNode; if (baseParent && base!==baseParent) { baseParent.replaceChild(base, initialBase); - } - if (!cbase && !toUnmount && component._parentComponent) { - initialBase._component = null; - recollectNodeTree(initialBase); + if (!toUnmount) { + initialBase._component = null; + recollectNodeTree(initialBase); + } } } @@ -170,7 +170,9 @@ export function renderComponent(component, opts, mountAll, isChild) { if (base && !isChild) { let componentRef = component, t = component; - while ((t=t._parentComponent)) { componentRef = t; } + while ((t=t._parentComponent)) { + (componentRef = t).base = base; + } base._component = componentRef; base._componentConstructor = componentRef.constructor; } @@ -179,8 +181,11 @@ export function renderComponent(component, opts, mountAll, isChild) { if (!isUpdate || mountAll) { mounts.unshift(component); } - else if (!skip && component.componentDidUpdate) { - component.componentDidUpdate(previousProps, previousState, previousContext); + else if (!skip) { + if (component.componentDidUpdate) { + component.componentDidUpdate(previousProps, previousState, previousContext); + } + if (options.afterUpdate) options.afterUpdate(component); } let cb = component._renderCallbacks, fn; @@ -218,7 +223,11 @@ export function buildComponentFromVNode(dom, vnode, context, mountAll) { } c = createComponent(vnode.nodeName, props, context); - if (dom && !c.nextBase) c.nextBase = dom; + if (dom && !c.nextBase) { + c.nextBase = dom; + // passing dom/oldDom as nextBase will recycle it if unused, so bypass recycling on L241: + oldDom = null; + } setComponentProps(c, props, SYNC_RENDER, context, mountAll); dom = c.base; @@ -239,6 +248,8 @@ export function buildComponentFromVNode(dom, vnode, context, mountAll) { * @private */ export function unmountComponent(component, remove) { + if (options.beforeUnmount) options.beforeUnmount(component); + // console.log(`${remove?'Removing':'Unmounting'} component: ${component.constructor.name}`); let base = component.base; diff --git a/thirdparty/preact/src/vdom/diff.js b/thirdparty/preact/src/vdom/diff.js index 691434e98..794a79aaa 100644 --- a/thirdparty/preact/src/vdom/diff.js +++ b/thirdparty/preact/src/vdom/diff.js @@ -6,6 +6,7 @@ import { buildComponentFromVNode } from './component'; import { setAccessor } from '../dom/index'; import { createNode, collectNode } from '../dom/recycler'; import { unmountComponent } from './component'; +import options from '../options'; /** Diff recursion count, used to track the end of the diff cycle. */ @@ -20,6 +21,7 @@ let isSvgMode = false; export function flushMounts() { let c; while ((c=mounts.pop())) { + if (options.afterMount) options.afterMount(c); if (c.componentDidMount) c.componentDidMount(); } } @@ -52,7 +54,9 @@ function idiff(dom, vnode, context, mountAll) { if (isString(vnode)) { if (dom) { if (dom instanceof Text && dom.parentNode) { - dom.nodeValue = vnode; + if (dom.nodeValue!=vnode) { + dom.nodeValue = vnode; + } return dom; } recollectNodeTree(dom); @@ -66,7 +70,8 @@ function idiff(dom, vnode, context, mountAll) { let out = dom, nodeName = vnode.nodeName, - prevSvgMode = isSvgMode; + prevSvgMode = isSvgMode, + vchildren = vnode.children; if (!isString(nodeName)) { nodeName = String(nodeName); @@ -86,11 +91,13 @@ function idiff(dom, vnode, context, mountAll) { } // fast-path for elements containing a single TextNode: - if (vnode.children && vnode.children.length===1 && typeof vnode.children[0]==='string' && out.childNodes.length===1 && out.firstChild instanceof Text) { - out.firstChild.nodeValue = vnode.children[0]; + if (vchildren && vchildren.length===1 && typeof vchildren[0]==='string' && out.childNodes.length===1 && out.firstChild instanceof Text) { + if (out.firstChild.nodeValue!=vchildren[0]) { + out.firstChild.nodeValue = vchildren[0]; + } } - else if (vnode.children || out.firstChild) { - innerDiffNode(out, vnode.children, context, mountAll); + else if (vchildren && vchildren.length || out.firstChild) { + innerDiffNode(out, vchildren, context, mountAll); } let props = out[ATTR_KEY]; @@ -232,15 +239,15 @@ export function recollectNodeTree(node, unmountOnly) { function diffAttributes(dom, attrs, old) { for (let name in old) { if (!(attrs && name in attrs) && old[name]!=null) { - setAccessor(dom, name, null, old[name], isSvgMode); + setAccessor(dom, name, old[name], old[name] = undefined, isSvgMode); } } // new & updated if (attrs) { for (let name in attrs) { - if (!(name in old) || attrs[name]!==(name==='value' || name==='checked' ? dom[name] : old[name])) { - setAccessor(dom, name, attrs[name], old[name], isSvgMode); + if (name!=='children' && name!=='innerHTML' && (!(name in old) || attrs[name]!==(name==='value' || name==='checked' ? dom[name] : old[name]))) { + setAccessor(dom, name, old[name], old[name] = attrs[name], isSvgMode); } } } diff --git a/thirdparty/preact/src/vdom/index.js b/thirdparty/preact/src/vdom/index.js index 50d4ca2b9..f59fbae21 100644 --- a/thirdparty/preact/src/vdom/index.js +++ b/thirdparty/preact/src/vdom/index.js @@ -33,9 +33,10 @@ export function isNamedNode(node, nodeName) { * @returns {Object} props */ export function getNodeProps(vnode) { - let defaultProps = vnode.nodeName.defaultProps, - props = clone(vnode.attributes); + let props = clone(vnode.attributes); + props.children = vnode.children; + let defaultProps = vnode.nodeName.defaultProps; if (defaultProps) { for (let i in defaultProps) { if (props[i]===undefined) { @@ -44,7 +45,5 @@ export function getNodeProps(vnode) { } } - if (vnode.children) props.children = vnode.children; - return props; } |