UNPKG

2.74 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _createClass = function () { 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, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
9var _outDateableActions, _modifierActions;
10
11var _consts = require('./consts');
12
13function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
15function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
17var outDateableActions = (_outDateableActions = {}, _defineProperty(_outDateableActions, _consts.LOAD_SUCCESS, _consts.LOAD_SUCCESS), _defineProperty(_outDateableActions, _consts.CREATE_SUCCESS, _consts.CREATE_SUCCESS), _defineProperty(_outDateableActions, _consts.UPDATE_SUCCESS, _consts.UPDATE_SUCCESS), _defineProperty(_outDateableActions, _consts.REMOVE_SUCCESS, _consts.REMOVE_SUCCESS), _outDateableActions);
18
19var modifierActions = (_modifierActions = {}, _defineProperty(_modifierActions, _consts.CREATE_REQUEST, _consts.CREATE_REQUEST), _defineProperty(_modifierActions, _consts.UPDATE_REQUEST, _consts.UPDATE_REQUEST), _defineProperty(_modifierActions, _consts.REMOVE_REQUEST, _consts.REMOVE_REQUEST), _modifierActions);
20
21var Outdated = function () {
22 function Outdated() {
23 _classCallCheck(this, Outdated);
24
25 this.timestamps = {};
26 }
27
28 _createClass(Outdated, [{
29 key: 'reportChange',
30 value: function reportChange(action) {
31 if (!modifierActions[action.type]) {
32 return;
33 }
34
35 var _action$meta = action.meta,
36 schema = _action$meta.schema,
37 timestamp = _action$meta.timestamp;
38
39 this.timestamps[schema] = timestamp;
40 }
41 }, {
42 key: 'isOutdated',
43 value: function isOutdated(action) {
44 var _action$meta2 = action.meta,
45 schema = _action$meta2.schema,
46 timestamp = _action$meta2.timestamp;
47
48
49 if (!outDateableActions[action.type]) {
50 return false;
51 }
52 if (!this.timestamps[schema]) {
53 return false;
54 }
55
56 return this.timestamps[schema] > timestamp;
57 }
58 }]);
59
60 return Outdated;
61}();
62
63exports.default = Outdated;
\No newline at end of file