UNPKG

@shopify/react-native-skia

Version:

High-performance React Native Graphics using Skia

128 lines (95 loc) 2.65 kB
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } export class JsiNode { constructor(ctx, type, props) { this.type = type; this.props = props; _defineProperty(this, "_children", []); _defineProperty(this, "Skia", void 0); _defineProperty(this, "depMgr", void 0); this.Skia = ctx.Skia; this.depMgr = ctx.depMgr; } setProps(props) { this.props = props; } setProp(name, v) { const hasChanged = this.props[name] !== v; this.props[name] = v; return hasChanged; } getProps() { return this.props; } children() { return this._children; } addChild(child) { this._children.push(child); } dispose() { this.depMgr.unsubscribeNode(this); this._children.forEach(child => child.dispose()); } removeChild(child) { const index = this._children.indexOf(child); if (index !== -1) { const [node] = this._children.splice(index, 1); node.dispose(); } } insertChildBefore(child, before) { const index = this._children.indexOf(child); if (index !== -1) { this._children.splice(index, 1); } const beforeIndex = this._children.indexOf(before); this._children.splice(beforeIndex, 0, child); } } export class JsiDeclarationNode extends JsiNode { constructor(ctx, declarationType, type, props) { super(ctx, type, props); this.declarationType = declarationType; _defineProperty(this, "invalidate", () => {}); } decorateChildren(ctx) { this.children().forEach(child => { if (child instanceof JsiDeclarationNode) { child.decorate(ctx); } }); } addChild(child) { if (!(child instanceof JsiDeclarationNode)) { throw new Error(`Cannot add child of type ${child.type} to ${this.type}`); } super.addChild(child); this.invalidate(); } insertChildBefore(child, before) { if (!(child instanceof JsiDeclarationNode)) { throw new Error(`Cannot add child of type ${child.type} to ${this.type}`); } super.insertChildBefore(child, before); this.invalidate(); } dispose() { this.invalidate(); super.dispose(); } setInvalidate(invalidate) { this.invalidate = invalidate; } setProps(props) { super.setProps(props); this.invalidate(); } setProp(name, v) { const hasChanged = super.setProp(name, v); if (hasChanged) { this.invalidate(); } return hasChanged; } } //# sourceMappingURL=Node.js.map