@turbox3d/reactivity
Version:
Large-scale reactive state management library
82 lines • 3.46 kB
JavaScript
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
import { ctx } from '../const/config';
import { EEventName, emitter } from './event';
export var MaterialCallStack = /*#__PURE__*/function () {
function MaterialCallStack() {
_classCallCheck(this, MaterialCallStack);
this.stack = [];
this.pendingToPopStack = [];
this.stackId = 0;
}
return _createClass(MaterialCallStack, [{
key: "push",
value: function push(item) {
this.stackId += 1;
var record = _objectSpread(_objectSpread({}, item), {}, {
stackId: this.stackId
});
this.currentStack = record;
this.stack.push(record);
if (ctx.devTool) {
emitter.emit(EEventName.materialCallStackChange, {
stack: _toConsumableArray(this.stack),
action: 'PUSH',
time: Date.now(),
currentStack: record
});
}
return this.stackId;
}
}, {
key: "pop",
value: function pop(stackId) {
var _a;
if (this.stack.length === 0) {
return;
}
if (this.stack[this.stack.length - 1].stackId !== stackId) {
this.pendingToPopStack.unshift(stackId);
} else {
this.currentStack = undefined;
var data = this.stack.pop();
if (ctx.devTool) {
emitter.emit(EEventName.materialCallStackChange, {
stack: _toConsumableArray(this.stack),
action: 'POP',
time: Date.now(),
currentStack: data
});
}
}
var newPendingToPopStack = _toConsumableArray(this.pendingToPopStack);
for (var index = 0; index < this.pendingToPopStack.length; index += 1) {
var id = this.pendingToPopStack[index];
if (((_a = this.stack[this.stack.length - 1]) === null || _a === void 0 ? void 0 : _a.stackId) === id) {
var _data = this.stack.pop();
newPendingToPopStack.splice(index, 1);
this.currentStack = this.stack[this.stack.length - 1];
if (ctx.devTool) {
emitter.emit(EEventName.materialCallStackChange, {
stack: _toConsumableArray(this.stack),
action: 'POP',
time: Date.now(),
currentStack: _data
});
}
} else {
break;
}
}
this.pendingToPopStack = newPendingToPopStack;
if (this.pendingToPopStack.length === 0) {
this.currentStack = undefined;
}
}
}]);
}();
export var materialCallStack = new MaterialCallStack();