171 lines
4.9 KiB
JavaScript
171 lines
4.9 KiB
JavaScript
// Metro module 591 (f592).
|
|
import { ChangeListeners } from "./Module592";
|
|
import batchEmitChanges from "./batchEmitChanges";
|
|
import Module10 from "./Module10";
|
|
import Module38 from "./Module38";
|
|
import { $withEnv } from "../_hermes/prelude";
|
|
let env535 = {};
|
|
const c535_4 = [];
|
|
env535[5] = false;
|
|
const promise = new Promise((resolve) => {
|
|
let env12385;
|
|
const r1 = env12385 = {
|
|
$parent: env535
|
|
};
|
|
env12385[0] = resolve;
|
|
env535[3] = $withEnv(() => {
|
|
(0, env12385[0])();
|
|
env535[3] = null;
|
|
}, r1);
|
|
});
|
|
export class Store {
|
|
static initialized = promise;
|
|
constructor(a0, a1, a2) {
|
|
let r5 = a1;
|
|
this._changeCallbacks = new ChangeListeners();
|
|
this._reactChangeCallbacks = new ChangeListeners();
|
|
this._syncWiths = [];
|
|
this._isInitialized = false;
|
|
this.doEmitChanges = (a0) => {
|
|
if (this._changeCallbacks.hasAny() || this._reactChangeCallbacks.hasAny() || this._syncWiths.length > 0) {
|
|
batchEmitChanges.markChanged(this);
|
|
if (batchEmitChanges.getIsPaused() && this._mustEmitChanges != null && this._mustEmitChanges(a0)) {
|
|
batchEmitChanges.resume(false);
|
|
}
|
|
}
|
|
};
|
|
this.addChangeListener = this._changeCallbacks.add;
|
|
this.removeChangeListener = this._changeCallbacks.remove;
|
|
this.addConditionalChangeListener = this._changeCallbacks.addConditional;
|
|
this.removeAllConditionalChangeListeners = this._changeCallbacks.removeAllConditional;
|
|
this.addReactChangeListener = this._reactChangeCallbacks.add;
|
|
this.removeReactChangeListener = this._reactChangeCallbacks.remove;
|
|
this._dispatcher = a0;
|
|
this._dispatchToken = this._dispatcher.createToken();
|
|
if (a1 == null) {
|
|
r5 = {};
|
|
}
|
|
this.registerActionHandlers(r5, a2);
|
|
c535_4.push(this);
|
|
if (env535[5]) {
|
|
this.initializeIfNeeded();
|
|
}
|
|
}
|
|
static initialize() {
|
|
env535[5] = true;
|
|
c535_4.forEach((item) => item.initializeIfNeeded());
|
|
if (env535[3] != null) {
|
|
const r12 = env535[3].$env;
|
|
(0, r12[0])();
|
|
r12.$parent[3] = null;
|
|
}
|
|
}
|
|
static destroy() {
|
|
c535_4.length = 0;
|
|
batchEmitChanges.destroy();
|
|
}
|
|
static getAll() {
|
|
return c535_4;
|
|
}
|
|
static removeAllConditionalListeners() {
|
|
c535_4.forEach((item) => {
|
|
item._changeCallbacks.removeAllConditional();
|
|
});
|
|
}
|
|
registerActionHandlers(a0, a1) {
|
|
this._dispatcher.register(this.getName(), a0, this.doEmitChanges, a1, this._dispatchToken);
|
|
}
|
|
getName() {
|
|
let displayName = this.constructor.displayName;
|
|
if (displayName == null) {
|
|
displayName = this.constructor.name;
|
|
}
|
|
return displayName;
|
|
}
|
|
initializeIfNeeded() {
|
|
if (!this._isInitialized) {
|
|
const r8 = Date.now();
|
|
this.initialize();
|
|
this._isInitialized = true;
|
|
const r6 = Date.now() - r8;
|
|
if (r6 > 5) {
|
|
Module10.mark("🦥", this.getName() + ".initialize()", r6);
|
|
}
|
|
}
|
|
}
|
|
initialize() {}
|
|
syncWith(a0, a1, a2) {
|
|
let env12387 = {
|
|
$parent: env535
|
|
};
|
|
env12387[3] = this;
|
|
env12387[1] = a1;
|
|
let r12 = a2;
|
|
this.waitFor.apply(this, [...a0]);
|
|
if (a2 != null) {
|
|
env12387[2] = 0;
|
|
const wrapper = () => {
|
|
if (env12387[2] !== batchEmitChanges.getChangeSentinel()) {
|
|
env12387[2] = batchEmitChanges.getChangeSentinel();
|
|
if ((0, env12387[1])() !== false) {
|
|
env12387[3].emitChange();
|
|
}
|
|
}
|
|
};
|
|
env12387[0] = wrapper;
|
|
if (a2 == null) {
|
|
r12 = 0;
|
|
}
|
|
let c12388_0 = r12;
|
|
const wrapper2 = wrapper;
|
|
let c12388_2 = null;
|
|
env12387[0] = r12 === 0 ? function() {
|
|
clearImmediate(c12388_2);
|
|
c12388_2 = setImmediate(wrapper2);
|
|
} : function() {
|
|
if (c12388_2 == null) {
|
|
c12388_2 = setTimeout(() => {
|
|
try {
|
|
wrapper2();
|
|
} catch (r5) {
|
|
c12388_2 = null;
|
|
throw r5;
|
|
}
|
|
c12388_2 = null;
|
|
}, c12388_0);
|
|
}
|
|
};
|
|
a0.forEach((item) => item.addChangeListener(env12387[0]));
|
|
} else {
|
|
a0.forEach((item) => {
|
|
item._syncWiths.push({
|
|
func: env12387[1],
|
|
store: env12387[3]
|
|
});
|
|
});
|
|
}
|
|
}
|
|
waitFor() {
|
|
const r7 = Array.prototype.slice.call(arguments, 0).map((item, index) => {
|
|
let r14 = null;
|
|
const r1 = item != null;
|
|
Module38(r1, `Store.waitFor(...) called with null Store at index ${index} for store ${this.getName()}`);
|
|
if (item._dispatcher != null) {
|
|
Module38(item._dispatcher === this._dispatcher, "Stores belong to two separate dispatchers.");
|
|
r14 = item.getDispatchToken();
|
|
}
|
|
return r14;
|
|
});
|
|
this._dispatcher.addDependencies(this.getDispatchToken(), r7.filter((item) => item != null));
|
|
}
|
|
emitChange() {
|
|
batchEmitChanges.markChanged(this);
|
|
}
|
|
getDispatchToken() {
|
|
return this._dispatchToken;
|
|
}
|
|
mustEmitChanges(_mustEmitChanges = () => true) {
|
|
this._mustEmitChanges = _mustEmitChanges;
|
|
}
|
|
}
|