store.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. exports.__esModule = true;
  3. var _map = require("babel-runtime/core-js/map");
  4. var _map2 = _interopRequireDefault(_map);
  5. var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
  6. var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
  7. var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");
  8. var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
  9. var _inherits2 = require("babel-runtime/helpers/inherits");
  10. var _inherits3 = _interopRequireDefault(_inherits2);
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. var Store = function (_Map) {
  13. (0, _inherits3.default)(Store, _Map);
  14. function Store() {
  15. (0, _classCallCheck3.default)(this, Store);
  16. var _this = (0, _possibleConstructorReturn3.default)(this, _Map.call(this));
  17. _this.dynamicData = {};
  18. return _this;
  19. }
  20. Store.prototype.setDynamic = function setDynamic(key, fn) {
  21. this.dynamicData[key] = fn;
  22. };
  23. Store.prototype.get = function get(key) {
  24. if (this.has(key)) {
  25. return _Map.prototype.get.call(this, key);
  26. } else {
  27. if (Object.prototype.hasOwnProperty.call(this.dynamicData, key)) {
  28. var val = this.dynamicData[key]();
  29. this.set(key, val);
  30. return val;
  31. }
  32. }
  33. };
  34. return Store;
  35. }(_map2.default);
  36. exports.default = Store;
  37. module.exports = exports["default"];