1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.Register = Register;
|
7 | exports['default'] = Cat;
|
8 |
|
9 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
10 |
|
11 | var _stampit = require('stampit');
|
12 |
|
13 | var _stampit2 = _interopRequireDefault(_stampit);
|
14 |
|
15 | var _invariant = require('invariant');
|
16 |
|
17 | var _invariant2 = _interopRequireDefault(_invariant);
|
18 |
|
19 | var _warning = require('warning');
|
20 |
|
21 | var _warning2 = _interopRequireDefault(_warning);
|
22 |
|
23 | var _debug = require('debug');
|
24 |
|
25 | var _debug2 = _interopRequireDefault(_debug);
|
26 |
|
27 | var _utils = require('./utils');
|
28 |
|
29 | var debug = (0, _debug2['default'])('thundercats:cat');
|
30 |
|
31 | function Register(map, Factory, constructorArgs) {
|
32 | var name = (0, _utils.getName)(Factory);
|
33 | if (map.has(name.toLowerCase())) {
|
34 | return (0, _warning2['default'])(false, 'Attempted to add a class, %s, that already exists', name);
|
35 | }
|
36 | var instance = Factory.apply(null, constructorArgs);
|
37 | debug('registering %s %s', (0, _utils.isStore)(Factory) ? 'store' : 'action', name);
|
38 | map.set(name.toLowerCase(), instance);
|
39 | return map;
|
40 | }
|
41 |
|
42 | var methods = {
|
43 | register: function register(StoreOrActions) {
|
44 | var name = (0, _utils.getNameOrNull)(StoreOrActions);
|
45 |
|
46 | (0, _invariant2['default'])(typeof name === 'string', 'Attempted to add a Store/Actions that does not have a displayName');
|
47 |
|
48 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
49 | args[_key - 1] = arguments[_key];
|
50 | }
|
51 |
|
52 | return Register((0, _utils.isStore)(StoreOrActions) ? this.stores : this.actions, StoreOrActions, args);
|
53 | },
|
54 |
|
55 | getStore: function getStore(store) {
|
56 | return this.stores.get(('' + store).toLowerCase());
|
57 | },
|
58 |
|
59 | getActions: function getActions(action) {
|
60 | return this.actions.get(('' + action).toLowerCase());
|
61 | },
|
62 |
|
63 | get: function get(storeOrActions) {
|
64 | var possibleStore = this.getStore(storeOrActions);
|
65 | return possibleStore ? possibleStore : this.getActions(storeOrActions);
|
66 | },
|
67 |
|
68 | dispose: function dispose() {
|
69 | debug('dispose all the things');
|
70 | this.stores.forEach(function (store) {
|
71 | store.dispose();
|
72 | });
|
73 |
|
74 | this.actions.forEach(function (action) {
|
75 | action.dispose();
|
76 | });
|
77 | }
|
78 | };
|
79 |
|
80 | function Cat() {
|
81 | return (0, _stampit2['default'])().init(function (_ref) {
|
82 | var instance = _ref.instance;
|
83 |
|
84 | instance.stores = new Map();
|
85 | instance.actions = new Map();
|
86 | }).methods(methods);
|
87 | } |
\ | No newline at end of file |