Skip to content

Commit

Permalink
Merge pull request #19 from cesbit/ts
Browse files Browse the repository at this point in the history
Added Ts
  • Loading branch information
joente authored Jun 14, 2024
2 parents 6d2afa1 + 9fac6de commit b05b50a
Show file tree
Hide file tree
Showing 11 changed files with 2,701 additions and 6,135 deletions.
26 changes: 4 additions & 22 deletions lib/actions.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,35 @@
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createActions = exports.Actions = void 0;

var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _invariant = _interopRequireDefault(require("invariant"));

/* global process */

/* eslint no-console: ["error", { allow: ["warn", "error"] }] */
var Actions = /*#__PURE__*/function () {
var Actions = exports.Actions = /*#__PURE__*/function () {
function Actions(names) {
var _this = this;

(0, _classCallCheck2["default"])(this, Actions);
this._callbacks = names.reduce(function (o, action) {
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;
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;
var onKey = "on".concat(action.charAt(0).toUpperCase()).concat(action.substr(1));

_this[action] = function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}

return _this._on(onKey, args);
};

o[onKey] = [];
return o;
}, {});
}

(0, _createClass2["default"])(Actions, [{
return (0, _createClass2["default"])(Actions, [{
key: "_on",
value: function _on(onKey, payload) {
this._callbacks[onKey].forEach(function (cb) {
Expand All @@ -60,13 +48,7 @@ var Actions = /*#__PURE__*/function () {
}
}
}]);
return Actions;
}();

exports.Actions = Actions;

var createActions = function createActions(names) {
var createActions = exports.createActions = function createActions(names) {
return new Actions(names);
};

exports.createActions = createActions;
};
60 changes: 12 additions & 48 deletions lib/component.js
Original file line number Diff line number Diff line change
@@ -1,90 +1,65 @@
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _react = _interopRequireDefault(require("react"));

var _store = _interopRequireDefault(require("./store"));

var _states = _interopRequireDefault(require("./states"));

var _invariant = _interopRequireDefault(require("invariant"));

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

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)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /* global process */
var ComponentFactory = function ComponentFactory(SuperClass) {
var Component = /*#__PURE__*/function (_SuperClass) {
(0, _inherits2["default"])(Component, _SuperClass);

var _super = _createSuper(Component);

function Component(props) {
var _this;

(0, _classCallCheck2["default"])(this, Component);
_this = _super.call(this, props);
_this = _callSuper(this, Component, [props]);
_this._vlowStores_ = {};
_this._vlowState_ = _states["default"].init;
_this._vlowTmpState = null;
return _this;
}

(0, _createClass2["default"])(Component, [{
(0, _inherits2["default"])(Component, _SuperClass);
return (0, _createClass2["default"])(Component, [{
key: "_vlowRegisterStore_",
value: function _vlowRegisterStore_(store) {
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; // Debug only valid props

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;
// Debug only valid props
if (process.env.NODE_ENV !== 'production') {
(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);

if (typeof store !== 'function') {
var invalidProps = Object.keys(store).filter(function (k) {
return k !== 'store' && k !== 'keys' && k !== 'altState';
});
(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);
}
} // End debug


var keys = store.keys;
var altState = store.altState;
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;
store = _store["default"]._vlowGetOrCreateStore(typeof store === 'function' ? store : store.store);

var id = store._vlowAddListener(this, keys, altState);

this._vlowStores_[id] = store;
this._vlowTmpState = this.state;
}
}, {
key: "mapStore",
value: function mapStore(store) {
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;

this._vlowRegisterStore_(store);
}
}, {
key: "mapStores",
value: function mapStores(stores) {
var _this2 = this;

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;
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;
stores.forEach(function (s) {
Expand All @@ -102,37 +77,26 @@ var ComponentFactory = function ComponentFactory(SuperClass) {
key: "componentWillUnmount",
value: function componentWillUnmount() {
var _this3 = this;

this._vlowState_ = _states["default"].stop;
Object.keys(this._vlowStores_).forEach(function (id) {
return _this3._vlowStores_[id]._vlowRemoveListener(id);
});
}
}]);
return Component;
}(SuperClass);

return Component;
};

var Component = /*#__PURE__*/function (_ComponentFactory) {
(0, _inherits2["default"])(Component, _ComponentFactory);

var _super2 = _createSuper(Component);

function Component() {
(0, _classCallCheck2["default"])(this, Component);
return _super2.apply(this, arguments);
return _callSuper(this, Component, arguments);
}

(0, _createClass2["default"])(Component, null, [{
(0, _inherits2["default"])(Component, _ComponentFactory);
return (0, _createClass2["default"])(Component, null, [{
key: "extend",
value: function extend(SuperClass) {
return ComponentFactory(SuperClass);
}
}]);
return Component;
}(ComponentFactory(_react["default"].Component));

var _default = Component;
exports["default"] = _default;
var _default = exports["default"] = Component;
12 changes: 3 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
value: true
});
Expand Down Expand Up @@ -30,15 +29,10 @@ Object.defineProperty(exports, "withVlow", {
return _withVlow["default"];
}
});

var _store = _interopRequireDefault(require("./store"));

var _component = _interopRequireDefault(require("./component"));

var _actions = require("./actions");

var _withVlow = _interopRequireDefault(require("./withVlow"));

/**
* Copyright (c) 2018-present, Cesbit
*
Expand All @@ -60,12 +54,12 @@ var _withVlow = _interopRequireDefault(require("./withVlow"));
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

var Vlow = {
version: '1.1.16'
version: '1.1.17'
};
Vlow.Store = _store["default"];
Vlow.Component = _component["default"];
Vlow.createActions = _actions.createActions;
Vlow.withVlow = _withVlow["default"];
var _default = Vlow;
exports["default"] = _default;
var _default = exports["default"] = Vlow;
4 changes: 1 addition & 3 deletions lib/states.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ var States = {
ready: 1,
// Component will be mounted.
stop: 2 // Component will be unmounted.

};
var _default = States;
exports["default"] = _default;
var _default = exports["default"] = States;
Loading

0 comments on commit b05b50a

Please sign in to comment.