diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-10-04 11:50:26 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-10-04 11:50:26 +0200 |
commit | 133a8c672c26609e9d56d4e184b779ca26971a8c (patch) | |
tree | f3aa4779a75279c95553cd68dd2a3bbe5e5b9dde /thirdparty/preact/src/vdom/component-recycler.js | |
parent | 0697c987c5314232056a86fa128b518c866d2f12 (diff) | |
parent | 30b577138dda685f65a8529be1866afa6e321845 (diff) |
Merge commit '30b577138dda685f65a8529be1866afa6e321845' as 'thirdparty/preact'
Diffstat (limited to 'thirdparty/preact/src/vdom/component-recycler.js')
-rw-r--r-- | thirdparty/preact/src/vdom/component-recycler.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/thirdparty/preact/src/vdom/component-recycler.js b/thirdparty/preact/src/vdom/component-recycler.js new file mode 100644 index 000000000..a70f0ece0 --- /dev/null +++ b/thirdparty/preact/src/vdom/component-recycler.js @@ -0,0 +1,32 @@ +import { Component } from '../component'; + +/** Retains a pool of Components for re-use, keyed on component name. + * Note: since component names are not unique or even necessarily available, these are primarily a form of sharding. + * @private + */ +const components = {}; + + +export function collectComponent(component) { + let name = component.constructor.name, + list = components[name]; + if (list) list.push(component); + else components[name] = [component]; +} + + +export function createComponent(Ctor, props, context) { + let inst = new Ctor(props, context), + list = components[Ctor.name]; + Component.call(inst, props, context); + if (list) { + for (let i=list.length; i--; ) { + if (list[i].constructor===Ctor) { + inst.nextBase = list[i].nextBase; + list.splice(i, 1); + break; + } + } + } + return inst; +} |