Sha256: 76f9c1ae2ae7fbd29a43f95d53b7189f7dea02ed6f1c8409628cca48ee86bae3
Contents?: true
Size: 1.15 KB
Versions: 92
Compression:
Stored size: 1.15 KB
Contents
import { Component } from '../component'; /** * Retains a pool of Components for re-use. * @type {Component[]} * @private */ export const recyclerComponents = []; /** * Create a component. Normalizes differences between PFC's and classful * Components. * @param {function} Ctor The constructor of the component to create * @param {object} props The initial props of the component * @param {object} context The initial context of the component * @returns {import('../component').Component} */ export function createComponent(Ctor, props, context) { let inst, i = recyclerComponents.length; if (Ctor.prototype && Ctor.prototype.render) { inst = new Ctor(props, context); Component.call(inst, props, context); } else { inst = new Component(props, context); inst.constructor = Ctor; inst.render = doRender; } while (i--) { if (recyclerComponents[i].constructor===Ctor) { inst.nextBase = recyclerComponents[i].nextBase; recyclerComponents.splice(i, 1); return inst; } } return inst; } /** The `.render()` method for a PFC backing instance. */ function doRender(props, state, context) { return this.constructor(props, context); }
Version data entries
92 entries across 92 versions & 1 rubygems