UNPKG

@difizen/magent-core

Version:
41 lines 2.63 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } var _dec, _class, _dec2, _class2; function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } import { Deferred, injectable } from '@difizen/mana-app'; export var DeferredModel = (_dec = injectable(), _dec(_class = /*#__PURE__*/_createClass(function DeferredModel() { _classCallCheck(this, DeferredModel); this.ready = void 0; this.readyDeferred = new Deferred(); this.ready = this.readyDeferred.promise; })) || _class); export var AsyncModel = (_dec2 = injectable(), _dec2(_class2 = /*#__PURE__*/function () { function AsyncModel() { _classCallCheck(this, AsyncModel); this.ready = void 0; this.readyDeferred = new Deferred(); this.ready = this.readyDeferred.promise; } _createClass(AsyncModel, [{ key: "initialize", value: function initialize(option) { var _this = this; setImmediate(function () { if (_this.shouldInitFromMeta(option)) { _this.fromMeta(option); } else { _this.fetchInfo(option); } }); } }, { key: "fromMeta", value: function fromMeta(option) { this.readyDeferred.resolve(this); } }]); return AsyncModel; }()) || _class2);