UNPKG

@shopify/react-native-skia

Version:

High-performance React Native Graphics using Skia

49 lines (38 loc) 1.61 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; } import { RNSkReadonlyValue } from "./RNSkReadonlyValue"; export class RNSkComputedValue extends RNSkReadonlyValue { constructor(callback, dependencies) { // Initialize dependencies - we can't call this yet, since // super if not called and it requires a start value to be set. const unsubscribers = []; const notifyUpdateRef = { current: undefined }; dependencies.forEach(dep => { if (dep && typeof dep === "object" && "__typename__" in dep && "addListener" in dep) { unsubscribers.push(dep.addListener(() => { var _notifyUpdateRef$curr; return (_notifyUpdateRef$curr = notifyUpdateRef.current) === null || _notifyUpdateRef$curr === void 0 ? void 0 : _notifyUpdateRef$curr.call(notifyUpdateRef); })); } }); super(callback()); _defineProperty(this, "_callback", void 0); _defineProperty(this, "_unsubscribers", void 0); this._unsubscribers = unsubscribers; notifyUpdateRef.current = this.dependecyUpdated.bind(this); this._callback = callback; } dependecyUpdated() { this.update(this._callback()); } unsubscribe() { this._unsubscribers.forEach(unsubscribe => unsubscribe()); this._unsubscribers = []; } dispose() { this._unsubscribers.forEach(unsubscribe => unsubscribe()); this._unsubscribers = []; } } //# sourceMappingURL=RNSkComputedValue.js.map