@shopify/react-native-skia
Version:
High-performance React Native Graphics using Skia
59 lines (44 loc) • 1.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.RNSkComputedValue = void 0;
var _RNSkReadonlyValue = require("./RNSkReadonlyValue");
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; }
class RNSkComputedValue extends _RNSkReadonlyValue.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 = [];
}
}
exports.RNSkComputedValue = RNSkComputedValue;
//# sourceMappingURL=RNSkComputedValue.js.map