Skip to content

Commit 29a3314

Browse files
committed
build
1 parent c691aa2 commit 29a3314

File tree

12 files changed

+99
-158
lines changed

12 files changed

+99
-158
lines changed

.babelrc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"presets": [
3-
"@babel/preset-env"
3+
[
4+
"@babel/preset-env",
5+
{
6+
"modules": false
7+
}
8+
]
49
],
510
"plugins": [
611
"@babel/plugin-proposal-class-properties",

lib/actions.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
"use strict";
2-
3-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4-
Object.defineProperty(exports, "__esModule", {
5-
value: true
6-
});
7-
exports.createActions = exports.Actions = void 0;
8-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11-
var _invariant = _interopRequireDefault(require("invariant"));
1+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3+
import _createClass from "@babel/runtime/helpers/createClass";
124
/* global process */
135
/* eslint no-console: ["error", { allow: ["warn", "error"] }] */
14-
var Actions = exports.Actions = /*#__PURE__*/function () {
6+
import invariant from 'invariant';
7+
var Actions = /*#__PURE__*/function () {
158
function Actions(names) {
169
var _this = this;
17-
(0, _classCallCheck2["default"])(this, Actions);
10+
_classCallCheck(this, Actions);
1811
this._callbacks = names.reduce(function (o, action) {
19-
typeof action !== 'string' || !action.length || action.charAt(0) === '_' ? process.env.NODE_ENV !== 'production' ? (0, _invariant["default"])(false, 'Cannot use action `%s`. Each action must be a sting with at least one character and cannot start with an underscore.', action) : (0, _invariant["default"])(false) : undefined;
20-
Object.prototype.hasOwnProperty.call(_this, action) ? process.env.NODE_ENV !== 'production' ? (0, _invariant["default"])(false, 'Action `%s` is already set (duplicate actions are not allowed).', action) : (0, _invariant["default"])(false) : undefined;
12+
typeof action !== 'string' || !action.length || action.charAt(0) === '_' ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Cannot use action `%s`. Each action must be a sting with at least one character and cannot start with an underscore.', action) : invariant(false) : undefined;
13+
Object.prototype.hasOwnProperty.call(_this, action) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Action `%s` is already set (duplicate actions are not allowed).', action) : invariant(false) : undefined;
2114
var onKey = "on".concat(action.charAt(0).toUpperCase()).concat(action.substr(1));
2215
_this[action] = function () {
2316
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -29,11 +22,11 @@ var Actions = exports.Actions = /*#__PURE__*/function () {
2922
return o;
3023
}, {});
3124
}
32-
return (0, _createClass2["default"])(Actions, [{
25+
return _createClass(Actions, [{
3326
key: "_on",
3427
value: function _on(onKey, payload) {
3528
this._callbacks[onKey].forEach(function (cb) {
36-
return cb.apply(void 0, (0, _toConsumableArray2["default"])(payload));
29+
return cb.apply(void 0, _toConsumableArray(payload));
3730
});
3831
}
3932
}, {
@@ -49,6 +42,7 @@ var Actions = exports.Actions = /*#__PURE__*/function () {
4942
}
5043
}]);
5144
}();
52-
var createActions = exports.createActions = function createActions(names) {
45+
var createActions = function createActions(names) {
5346
return new Actions(names);
54-
};
47+
};
48+
export { Actions, createActions };

lib/component.js

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,45 @@
1-
"use strict";
2-
3-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4-
Object.defineProperty(exports, "__esModule", {
5-
value: true
6-
});
7-
exports["default"] = void 0;
8-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
11-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
12-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
13-
var _react = _interopRequireDefault(require("react"));
14-
var _invariant = _interopRequireDefault(require("invariant"));
15-
var _store = _interopRequireDefault(require("./store.js"));
16-
var _states = _interopRequireDefault(require("./states.js"));
17-
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
18-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /* global process */
1+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2+
import _createClass from "@babel/runtime/helpers/createClass";
3+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
4+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
5+
import _inherits from "@babel/runtime/helpers/inherits";
6+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
7+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
8+
/* global process */
9+
import React from 'react';
10+
import invariant from 'invariant';
11+
import Store from './store.js';
12+
import States from './states.js';
1913
var ComponentFactory = function ComponentFactory(SuperClass) {
2014
var Component = /*#__PURE__*/function (_SuperClass) {
2115
function Component(props) {
2216
var _this;
23-
(0, _classCallCheck2["default"])(this, Component);
17+
_classCallCheck(this, Component);
2418
_this = _callSuper(this, Component, [props]);
2519
_this._vlowStores_ = [];
26-
_this._vlowState_ = _states["default"].init;
20+
_this._vlowState_ = States.init;
2721
_this._vlowTmpState = null;
2822
return _this;
2923
}
30-
(0, _inherits2["default"])(Component, _SuperClass);
31-
return (0, _createClass2["default"])(Component, [{
24+
_inherits(Component, _SuperClass);
25+
return _createClass(Component, [{
3226
key: "_vlowRegisterStore_",
3327
value: function _vlowRegisterStore_(store) {
34-
this._vlowState_ !== _states["default"].init ? process.env.NODE_ENV !== 'production' ? (0, _invariant["default"])(false, 'Component `%s` is trying to register a store outside the constructor.', this.constructor.name) : (0, _invariant["default"])(false) : undefined;
28+
this._vlowState_ !== States.init ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Component `%s` is trying to register a store outside the constructor.', this.constructor.name) : invariant(false) : undefined;
3529
// Debug only valid props
3630
if (process.env.NODE_ENV !== 'production') {
37-
(0, _invariant["default"])(store.constructor !== Array, 'Component `%s` is registering a store using an Array, most likely you are using `.mapStore()` instead of `.mapStores()`.', this.constructor.name);
31+
invariant(store.constructor !== Array, 'Component `%s` is registering a store using an Array, most likely you are using `.mapStore()` instead of `.mapStores()`.', this.constructor.name);
3832
if (typeof store !== 'function') {
3933
var invalidProps = Object.keys(store).filter(function (k) {
4034
return k !== 'store' && k !== 'keys' && k !== 'altState';
4135
});
42-
(0, _invariant["default"])(!invalidProps.length, 'Component `%s` is registering a store using invalid properties: `%s` (only `store`, `keys` and `altState` are allowed).', this.constructor.name, invalidProps);
36+
invariant(!invalidProps.length, 'Component `%s` is registering a store using invalid properties: `%s` (only `store`, `keys` and `altState` are allowed).', this.constructor.name, invalidProps);
4337
}
4438
} // End debug
4539
var keys = store.keys;
4640
var altState = store.altState;
47-
keys && altState ? process.env.NODE_ENV !== 'production' ? (0, _invariant["default"])(false, 'Component `%s` is registering a store using both `keys` and `altState` but they cannot be used at the same time.', this.constructor.name) : (0, _invariant["default"])(false) : undefined;
48-
store = _store["default"]._vlowGetOrCreateStore(typeof store === 'function' ? store : store.store);
41+
keys && altState ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Component `%s` is registering a store using both `keys` and `altState` but they cannot be used at the same time.', this.constructor.name) : invariant(false) : undefined;
42+
store = Store._vlowGetOrCreateStore(typeof store === 'function' ? store : store.store);
4943
if (!this._vlowStores_.includes(store)) {
5044
store._vlowAddListener(this, keys, altState);
5145
this._vlowStores_.push(store);
@@ -55,31 +49,31 @@ var ComponentFactory = function ComponentFactory(SuperClass) {
5549
}, {
5650
key: "mapStore",
5751
value: function mapStore(store) {
58-
this._vlowTmpState !== null ? process.env.NODE_ENV !== 'production' ? (0, _invariant["default"])(false, 'Component `%s` must only make one call to either `.mapStore()` or `.mapStores()`.', this.constructor.name) : (0, _invariant["default"])(false) : undefined;
52+
this._vlowTmpState !== null ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Component `%s` must only make one call to either `.mapStore()` or `.mapStores()`.', this.constructor.name) : invariant(false) : undefined;
5953
this._vlowRegisterStore_(store);
6054
}
6155
}, {
6256
key: "mapStores",
6357
value: function mapStores(stores) {
6458
var _this2 = this;
65-
this._vlowTmpState !== null ? process.env.NODE_ENV !== 'production' ? (0, _invariant["default"])(false, 'Component `%s` must only make one call to either `.mapStore()` or `.mapStores()`.', this.constructor.name) : (0, _invariant["default"])(false) : undefined;
66-
stores.constructor !== Array ? process.env.NODE_ENV !== 'production' ? (0, _invariant["default"])(false, 'Function `.mapStores()` on Component `%s` is expecting an Array got got `%s`.', this.constructor.name, stores) : (0, _invariant["default"])(false) : undefined;
59+
this._vlowTmpState !== null ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Component `%s` must only make one call to either `.mapStore()` or `.mapStores()`.', this.constructor.name) : invariant(false) : undefined;
60+
stores.constructor !== Array ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Function `.mapStores()` on Component `%s` is expecting an Array got got `%s`.', this.constructor.name, stores) : invariant(false) : undefined;
6761
stores.forEach(function (s) {
6862
return _this2._vlowRegisterStore_(s);
6963
});
7064
}
7165
}, {
7266
key: "componentDidMount",
7367
value: function componentDidMount() {
74-
this._vlowState_ = _states["default"].ready;
75-
!!this._vlowTmpState && this._vlowTmpState !== this.state ? process.env.NODE_ENV !== 'production' ? (0, _invariant["default"])(false, 'Component `%s` state has been overwritten after registering a store.', this.constructor.name) : (0, _invariant["default"])(false) : undefined;
68+
this._vlowState_ = States.ready;
69+
!!this._vlowTmpState && this._vlowTmpState !== this.state ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Component `%s` state has been overwritten after registering a store.', this.constructor.name) : invariant(false) : undefined;
7670
delete this._vlowTmpState;
7771
}
7872
}, {
7973
key: "componentWillUnmount",
8074
value: function componentWillUnmount() {
8175
var _this3 = this;
82-
this._vlowState_ = _states["default"].stop;
76+
this._vlowState_ = States.stop;
8377
this._vlowStores_.forEach(function (store) {
8478
return store._vlowRemoveListener(_this3);
8579
});
@@ -90,15 +84,15 @@ var ComponentFactory = function ComponentFactory(SuperClass) {
9084
};
9185
var Component = /*#__PURE__*/function (_ComponentFactory) {
9286
function Component() {
93-
(0, _classCallCheck2["default"])(this, Component);
87+
_classCallCheck(this, Component);
9488
return _callSuper(this, Component, arguments);
9589
}
96-
(0, _inherits2["default"])(Component, _ComponentFactory);
97-
return (0, _createClass2["default"])(Component, null, [{
90+
_inherits(Component, _ComponentFactory);
91+
return _createClass(Component, null, [{
9892
key: "extend",
9993
value: function extend(SuperClass) {
10094
return ComponentFactory(SuperClass);
10195
}
10296
}]);
103-
}(ComponentFactory(_react["default"].Component));
104-
var _default = exports["default"] = Component;
97+
}(ComponentFactory(React.Component));
98+
export default Component;

lib/index.js

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,3 @@
1-
"use strict";
2-
3-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4-
Object.defineProperty(exports, "__esModule", {
5-
value: true
6-
});
7-
Object.defineProperty(exports, "Component", {
8-
enumerable: true,
9-
get: function get() {
10-
return _component["default"];
11-
}
12-
});
13-
Object.defineProperty(exports, "Store", {
14-
enumerable: true,
15-
get: function get() {
16-
return _store["default"];
17-
}
18-
});
19-
Object.defineProperty(exports, "createActions", {
20-
enumerable: true,
21-
get: function get() {
22-
return _actions.createActions;
23-
}
24-
});
25-
exports["default"] = void 0;
26-
Object.defineProperty(exports, "withVlow", {
27-
enumerable: true,
28-
get: function get() {
29-
return _withVlow["default"];
30-
}
31-
});
32-
var _store = _interopRequireDefault(require("./store.js"));
33-
var _component = _interopRequireDefault(require("./component.js"));
34-
var _actions = require("./actions.js");
35-
var _withVlow = _interopRequireDefault(require("./withVlow.js"));
361
/**
372
* Copyright (c) 2018-present, Cesbit
383
*
@@ -54,12 +19,16 @@ var _withVlow = _interopRequireDefault(require("./withVlow.js"));
5419
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
5520
* SOFTWARE.
5621
*/
57-
22+
import Store from './store.js';
23+
import Component from './component.js';
24+
import { createActions } from './actions.js';
25+
import withVlow from './withVlow.js';
5826
var Vlow = {
59-
version: '1.1.20'
27+
version: '1.1.21'
6028
};
61-
Vlow.Store = _store["default"];
62-
Vlow.Component = _component["default"];
63-
Vlow.createActions = _actions.createActions;
64-
Vlow.withVlow = _withVlow["default"];
65-
var _default = exports["default"] = Vlow;
29+
Vlow.Store = Store;
30+
Vlow.Component = Component;
31+
Vlow.createActions = createActions;
32+
Vlow.withVlow = withVlow;
33+
export { Store, Component, createActions, withVlow };
34+
export default Vlow;

lib/states.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
"use strict";
2-
3-
Object.defineProperty(exports, "__esModule", {
4-
value: true
5-
});
6-
exports["default"] = void 0;
71
var States = {
82
init: 0,
93
// Component is being constructed.
104
ready: 1,
115
// Component will be mounted.
126
stop: 2 // Component will be unmounted.
137
};
14-
var _default = exports["default"] = States;
8+
export default States;

lib/store.js

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
1-
"use strict";
2-
3-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4-
Object.defineProperty(exports, "__esModule", {
5-
value: true
6-
});
7-
exports["default"] = void 0;
8-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11-
var _invariant = _interopRequireDefault(require("invariant"));
12-
var _states = _interopRequireDefault(require("./states.js"));
1+
import _extends from "@babel/runtime/helpers/extends";
2+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3+
import _createClass from "@babel/runtime/helpers/createClass";
134
/* global process */
145
/* eslint no-console: ["error", { allow: ["warn", "error"] }] */
15-
6+
import invariant from 'invariant';
7+
import States from './states.js';
168
var _stores = [];
179
var Store = /*#__PURE__*/function () {
1810
function Store() {
1911
var _this = this;
20-
(0, _classCallCheck2["default"])(this, Store);
12+
_classCallCheck(this, Store);
2113
this._vlowListeners_ = [];
2214
this.state = this.state || {}; // ensure state, may be overwritten in SubClass constructor
2315
for (var _len = arguments.length, actions = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -27,7 +19,7 @@ var Store = /*#__PURE__*/function () {
2719
return a._addStore(_this);
2820
});
2921
}
30-
return (0, _createClass2["default"])(Store, [{
22+
return _createClass(Store, [{
3123
key: "setState",
3224
value: function setState(newState, cb) {
3325
var _this2 = this;
@@ -37,7 +29,7 @@ var Store = /*#__PURE__*/function () {
3729
}
3830

3931
// update local state, this is not a real component so we can update the state immediately.
40-
this.state = (0, _extends2["default"])(this.state, newState);
32+
this.state = _extends(this.state, newState);
4133

4234
// get listeners
4335
var listeners = this._vlowListeners_;
@@ -94,14 +86,14 @@ var Store = /*#__PURE__*/function () {
9486
state = !listener.keys ? !listener.altState ? state : listener.altState(this.state, component.state, component.props) || {} : this._vlowFilterState(state, listener.keys);
9587
if (Object.keys(state).length) {
9688
switch (component._vlowState_) {
97-
case _states["default"].init:
98-
counter ? process.env.NODE_ENV !== 'production' ? (0, _invariant["default"])(false, 'Store `%s` is using `setState()` with a callback on component `%s` which is not yet mounted. This is not possible, make sure all components are mounted or remove the callback from setState.', this.constructor.name, component.constructor.name) : (0, _invariant["default"])(false) : undefined;
99-
component.state = (0, _extends2["default"])(component.state || {}, state);
89+
case States.init:
90+
counter ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Store `%s` is using `setState()` with a callback on component `%s` which is not yet mounted. This is not possible, make sure all components are mounted or remove the callback from setState.', this.constructor.name, component.constructor.name) : invariant(false) : undefined;
91+
component.state = _extends(component.state || {}, state);
10092
break;
101-
case _states["default"].ready:
93+
case States.ready:
10294
component.setState(state, counter);
10395
break;
104-
case _states["default"].stop:
96+
case States.stop:
10597
counter && counter.i--;
10698
break;
10799
}
@@ -166,4 +158,4 @@ var Store = /*#__PURE__*/function () {
166158
}
167159
}]);
168160
}();
169-
var _default = exports["default"] = Store;
161+
export default Store;

0 commit comments

Comments
 (0)