reactive-di
Advanced tools
Comparing version 2.4.2 to 3.0.0
'use strict'; | ||
exports.__esModule = true; | ||
exports.default = undefined; | ||
var _debugName = require('../utils/debugName'); | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
var _debugName2 = _interopRequireDefault(_debugName); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _shallowEqual = require('../utils/shallowEqual'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _shallowEqual2 = _interopRequireDefault(_shallowEqual); | ||
var ReactComponentFactory = function () { | ||
function ReactComponentFactory(react) { | ||
_classCallCheck(this, ReactComponentFactory); | ||
var _ComponentControllable = require('../core/ComponentControllable'); | ||
this.createElement = react.createElement; | ||
var _ComponentControllable2 = _interopRequireDefault(_ComponentControllable); | ||
this._Component = function (_react$Component) { | ||
_inherits(WrappedComponent, _react$Component); | ||
var _common = require('../core/common'); | ||
function WrappedComponent() { | ||
_classCallCheck(this, WrappedComponent); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
return _possibleConstructorReturn(this, _react$Component.apply(this, arguments)); | ||
} | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
WrappedComponent.prototype.componentWillMount = function componentWillMount() { | ||
this._consumer = this.constructor.__factory.create(this, this.props); | ||
}; | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
WrappedComponent.prototype.setProps = function setProps(props) { | ||
this.props = props; | ||
}; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
WrappedComponent.prototype.componentDidMount = function componentDidMount() { | ||
this._consumer.didMount(); | ||
}; | ||
// <State: Object, Props: Object> | ||
var ComponentMixin = { | ||
// static __rdiCtx: StaticContext<Props, State> | ||
// setState: (state: State) => void | ||
// state: ?State | ||
// props: Props | ||
// | ||
// _target: SrcComponent<Props, ?State> | ||
// _controllable: IComponentControllable<State, ReactComponentClass<Props, State>> | ||
// _createElement: ReactCreateElement | ||
WrappedComponent.prototype.componentDidUpdate = function componentDidUpdate() { | ||
this._consumer.didUpdate(); | ||
}; | ||
componentWillMount: function componentWillMount() { | ||
var ctx = this.constructor.__rdiCtx; | ||
var t = this; | ||
var setState = function setState(state) { | ||
return t.setState(state); | ||
}; | ||
var controllable = this._controllable = new _ComponentControllable2.default(ctx.info, setState); | ||
this._createElement = controllable.contextify(ctx.createElement); | ||
WrappedComponent.prototype.componentWillUnmount = function componentWillUnmount() { | ||
this._consumer.willUnmount(); | ||
}; | ||
this.state = controllable.getState(); | ||
this._target = ctx.info.target; | ||
this._controllable.onWillMount(this); | ||
}, | ||
componentDidMount: function componentDidMount() { | ||
this._controllable.onMount(); | ||
}, | ||
componentDidUpdate: function componentDidUpdate(_props, _state) { | ||
this._controllable.onUpdate(this); | ||
}, | ||
componentWillUnmount: function componentWillUnmount() { | ||
this._controllable.onUnmount(); | ||
}, | ||
shouldComponentUpdate: function shouldComponentUpdate(nextProps, nextState) { | ||
return !(0, _shallowEqual2.default)(this.props, nextProps) || !(0, _shallowEqual.shallowStrictEqual)(this.state, nextState); | ||
}, | ||
render: function render() { | ||
return this._target(this.props, this.state, this._createElement); | ||
} | ||
}; | ||
WrappedComponent.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) { | ||
return this._consumer.shouldUpdate(nextProps); | ||
}; | ||
var ComponentDevMixin = { | ||
_showError: function _showError(e) { | ||
console.error(e); // eslint-disable-line | ||
}, | ||
shouldComponentUpdate: function shouldComponentUpdate(nextProps, nextState) { | ||
return ComponentMixin.shouldComponentUpdate.call(this, nextProps, nextState); | ||
}, | ||
componentWillMount: function componentWillMount() { | ||
try { | ||
ComponentMixin.componentWillMount.call(this); | ||
} catch (e) { | ||
this._showError(e); | ||
throw e; | ||
} | ||
}, | ||
componentDidUpdate: function componentDidUpdate() { | ||
try { | ||
ComponentMixin.componentDidUpdate.call(this); | ||
} catch (e) { | ||
this._showError(e); | ||
throw e; | ||
} | ||
}, | ||
componentDidMount: function componentDidMount() { | ||
try { | ||
ComponentMixin.componentDidMount.call(this); | ||
} catch (e) { | ||
this._showError(e); | ||
throw e; | ||
} | ||
}, | ||
componentWillUnmount: function componentWillUnmount() { | ||
try { | ||
ComponentMixin.componentWillUnmount.call(this); | ||
} catch (e) { | ||
this._showError(e); | ||
throw e; | ||
} | ||
}, | ||
render: function render() { | ||
try { | ||
return ComponentMixin.render.call(this); | ||
} catch (e) { | ||
this._showError(e); | ||
throw e; | ||
} | ||
} | ||
}; | ||
WrappedComponent.prototype.render = function render() { | ||
return this._consumer.render(); | ||
}; | ||
var ReactComponentFactory = function () { | ||
function ReactComponentFactory(_ref, isDebug) { | ||
var Component = _ref.Component, | ||
createElement = _ref.createElement; | ||
_classCallCheck(this, ReactComponentFactory); | ||
this._createElement = createElement; | ||
this._Component = Component; | ||
this._mixin = isDebug ? ComponentDevMixin : ComponentMixin; | ||
return WrappedComponent; | ||
}(react.Component); | ||
} | ||
ReactComponentFactory.prototype.wrapComponent = function wrapComponent(info) { | ||
ReactComponentFactory.prototype.wrapComponent = function wrapComponent(factory) { | ||
var _class, _temp; | ||
var createElement = this._createElement; | ||
var WrappedComponent = (_temp = _class = function (_ref2) { | ||
_inherits(WrappedComponent, _ref2); | ||
return _temp = _class = function (_ref) { | ||
_inherits(WrappedComponent, _ref); | ||
@@ -140,13 +67,7 @@ function WrappedComponent() { | ||
return _possibleConstructorReturn(this, _ref2.apply(this, arguments)); | ||
return _possibleConstructorReturn(this, _ref.apply(this, arguments)); | ||
} | ||
return WrappedComponent; | ||
}(this._Component), _class.displayName = '' + (0, _debugName2.default)(info.target), _class.__rdiCtx = { | ||
info: info, | ||
createElement: createElement | ||
}, _temp); | ||
Object.assign(WrappedComponent.prototype, this._mixin); | ||
return WrappedComponent; | ||
}(this._Component), _class.displayName = factory.displayName, _class.__factory = factory, _temp; | ||
}; | ||
@@ -158,4 +79,2 @@ | ||
exports.default = ReactComponentFactory; | ||
if (0) new (Function.prototype.bind.apply(ReactComponentFactory, [null].concat(0)))(); // eslint-disable-line | ||
//# sourceMappingURL=ReactComponentFactory.js.map |
@@ -9,4 +9,3 @@ 'use strict'; | ||
exports.source = source; | ||
exports.updaters = updaters; | ||
exports.service = service; | ||
exports.actions = actions; | ||
exports.abstract = abstract; | ||
@@ -16,15 +15,9 @@ exports.hooks = hooks; | ||
var _CustomReflect = require('./CustomReflect'); | ||
var _GenericThemeHook = require('./theme/GenericThemeHook'); | ||
var _CustomReflect2 = _interopRequireDefault(_CustomReflect); | ||
var _GenericThemeHook2 = _interopRequireDefault(_GenericThemeHook); | ||
var _common = require('./core/common'); | ||
var _Updater = require('./core/Updater'); | ||
var _Updater2 = _interopRequireDefault(_Updater); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var dm = _CustomReflect2.default.defineMetadata; // eslint-disable-line | ||
/* eslint-disable no-param-reassign */ | ||
@@ -38,3 +31,3 @@ function deps() { | ||
if (args.length) { | ||
dm(_common.paramTypesKey, args, target); | ||
target._rdiArgs = args; | ||
} | ||
@@ -45,4 +38,5 @@ return target; | ||
function factory(target, isJsx) { | ||
dm(_common.subtypeKey, isJsx ? 'jsx' : 'func', target); | ||
function factory(target) { | ||
target._rdiFn = true; | ||
return target; | ||
@@ -53,4 +47,4 @@ } | ||
return function (target) { | ||
dm(_common.metaKey, new _common.ComponentMeta(rec || {}), target); | ||
dm(_common.subtypeKey, 'jsx', target); | ||
target._rdiJsx = true; | ||
target._rdiCmp = rec; | ||
return target; | ||
@@ -61,3 +55,3 @@ }; | ||
function theme(target) { | ||
dm(_common.metaKey, new _common.ThemeMeta(), target); | ||
target._rdiHook = _GenericThemeHook2.default; | ||
return target; | ||
@@ -68,3 +62,5 @@ } | ||
return function (target) { | ||
dm(_common.metaKey, new _common.SourceMeta(rec), target); | ||
target._rdiKey = rec.key; | ||
target._rdiInst = rec.instance || false; | ||
target._rdiLoaded = rec.loaded || false; | ||
return target; | ||
@@ -74,15 +70,4 @@ }; | ||
function updaters() { | ||
for (var _len2 = arguments.length, items = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
items[_key2] = arguments[_key2]; | ||
} | ||
return function (target) { | ||
dm(_common.metaKey, new _common.StatusMeta(items), target); | ||
return target; | ||
}; | ||
} | ||
function service(target) { | ||
dm(_common.metaKey, new _common.ServiceMeta(), target); | ||
function actions(target) { | ||
target._rdiEnd = true; | ||
return target; | ||
@@ -92,3 +77,3 @@ } | ||
function abstract(target) { | ||
dm(_common.metaKey, new _common.AbstractMeta(), target); | ||
target._rdiAbs = true; | ||
return target; | ||
@@ -99,4 +84,5 @@ } | ||
return function (lc) { | ||
dm(_common.lcKey, lc, target); | ||
dm(_common.metaKey, new _common.ServiceMeta(), lc); | ||
target._rdiHook = lc; | ||
lc._rdiEnd = true; | ||
return lc; | ||
@@ -109,4 +95,4 @@ }; | ||
function cloneComponent(src, rec) { | ||
function target(arg1, arg2, arg3) { | ||
return src(arg1, arg2, arg3); | ||
function target(arg1, arg2) { | ||
return src(arg1, arg2); | ||
} | ||
@@ -116,4 +102,5 @@ target.displayName = (src.displayName || src.name) + '#clone-' + (cloneNumber || '0'); | ||
Object.setPrototypeOf(target, src); | ||
target._rdiJsx = true; | ||
if (rec) { | ||
dm(_common.metaKey, new _common.ComponentMeta(rec), target); | ||
target._rdiCmp = rec; | ||
} | ||
@@ -120,0 +107,0 @@ |
'use strict'; | ||
exports.__esModule = true; | ||
exports.bindObservableToAtom = exports.ReactComponentFactory = exports.BaseModel = exports.UpdaterStatus = exports.Updater = exports.isComponent = exports.Di = undefined; | ||
exports.AbstractSheetFactory = exports.DiFactory = exports.IndexCollection = exports.RecoverableError = exports.Updater = exports.BaseModel = exports.refsSetter = exports.eventSetter = exports.setter = exports.debugName = exports.SourceStatus = exports.ReactComponentFactory = undefined; | ||
var _Di = require('./core/Di'); | ||
var _interfaces = require('./theme/interfaces'); | ||
var _Di2 = _interopRequireDefault(_Di); | ||
Object.defineProperty(exports, 'AbstractSheetFactory', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interfaces.AbstractSheetFactory; | ||
} | ||
}); | ||
var _common = require('./core/common'); | ||
var _DiFactory = require('./DiFactory'); | ||
var _ReactComponentFactory = require('./adapters/ReactComponentFactory'); | ||
var _DiFactory2 = _interopRequireDefault(_DiFactory); | ||
var _ReactComponentFactory2 = _interopRequireDefault(_ReactComponentFactory); | ||
var _IndexCollection = require('./utils/IndexCollection'); | ||
var _IndexCollection2 = _interopRequireDefault(_IndexCollection); | ||
var _refsSetter = require('./utils/refsSetter'); | ||
var _refsSetter2 = _interopRequireDefault(_refsSetter); | ||
var _Updater = require('./utils/Updater'); | ||
var _Updater2 = _interopRequireDefault(_Updater); | ||
var _BaseModel = require('./utils/BaseModel'); | ||
@@ -20,19 +35,29 @@ | ||
var _Updater = require('./core/Updater'); | ||
var _debugName = require('./utils/debugName'); | ||
var _Updater2 = _interopRequireDefault(_Updater); | ||
var _debugName2 = _interopRequireDefault(_debugName); | ||
var _bindObservableToAtom = require('./utils/bindObservableToAtom'); | ||
var _wrapObject = require('./utils/wrapObject'); | ||
var _bindObservableToAtom2 = _interopRequireDefault(_bindObservableToAtom); | ||
var _SourceStatus = require('./atoms/SourceStatus'); | ||
var _SourceStatus2 = _interopRequireDefault(_SourceStatus); | ||
var _ReactComponentFactory = require('./adapters/ReactComponentFactory'); | ||
var _ReactComponentFactory2 = _interopRequireDefault(_ReactComponentFactory); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.Di = _Di2.default; | ||
exports.isComponent = _common.isComponent; | ||
exports.ReactComponentFactory = _ReactComponentFactory2.default; | ||
exports.SourceStatus = _SourceStatus2.default; | ||
exports.debugName = _debugName2.default; | ||
exports.setter = _wrapObject.setter; | ||
exports.eventSetter = _wrapObject.eventSetter; | ||
exports.refsSetter = _refsSetter2.default; | ||
exports.BaseModel = _BaseModel2.default; | ||
exports.Updater = _Updater2.default; | ||
exports.UpdaterStatus = _Updater.UpdaterStatus; | ||
exports.BaseModel = _BaseModel2.default; | ||
exports.ReactComponentFactory = _ReactComponentFactory2.default; | ||
exports.bindObservableToAtom = _bindObservableToAtom2.default; | ||
exports.RecoverableError = _Updater.RecoverableError; | ||
exports.IndexCollection = _IndexCollection2.default; | ||
exports.DiFactory = _DiFactory2.default; | ||
//# sourceMappingURL=index.js.map |
@@ -1,6 +0,7 @@ | ||
"use strict"; | ||
'use strict'; | ||
exports.__esModule = true; | ||
exports.default = undefined; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _interfaces = require('../atoms/interfaces'); | ||
@@ -10,12 +11,20 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var BaseModel = function () { | ||
function BaseModel(rec) { | ||
function BaseModel() { | ||
_classCallCheck(this, BaseModel); | ||
Object.assign(this, this.constructor.defaults, rec); | ||
} | ||
BaseModel.prototype.copy = function copy(rec) { | ||
return new this.constructor(_extends({}, this, rec)); | ||
return Object.assign(Object.create(this.constructor.prototype), this, rec); | ||
}; | ||
BaseModel.prototype.set = function set(rec) { | ||
var val = this.copy(rec);this[_interfaces.setterKey].set(val); | ||
return val; | ||
}; | ||
BaseModel.prototype.reset = function reset() { | ||
var val = new this.constructor();this[_interfaces.setterKey].set(val); | ||
return val; | ||
}; | ||
return BaseModel; | ||
@@ -22,0 +31,0 @@ }(); |
{ | ||
"name": "reactive-di", | ||
"version": "2.4.2", | ||
"version": "3.0.0", | ||
"description": "Reactive dependency injection", | ||
@@ -26,2 +26,3 @@ "publishConfig": { | ||
"test.dev": "mocha --growl --watch", | ||
"analyze": "webpack --config examples/app/webpack.config.es5.js --json | webpack-bundle-size-analyzer", | ||
"start": "webpack-dev-server --config examples/app/webpack.config.es5.js --hot --history-api-fallback --inline" | ||
@@ -62,35 +63,41 @@ }, | ||
"babel-cli": "^6.18.0", | ||
"babel-core": "^6.18.2", | ||
"babel-loader": "^6.2.7", | ||
"babel-core": "^6.21.0", | ||
"babel-loader": "^6.2.10", | ||
"babel-plugin-espower": "^2.3.1", | ||
"babel-plugin-module-resolver": "^2.3.0", | ||
"babel-plugin-module-resolver": "^2.4.0", | ||
"babel-plugin-syntax-decorators": "^6.13.0", | ||
"babel-plugin-syntax-flow": "^6.18.0", | ||
"babel-plugin-transform-decorators-legacy": "^1.3.4", | ||
"babel-plugin-transform-flow-strip-types": "^6.18.0", | ||
"babel-polyfill": "^6.16.0", | ||
"babel-plugin-transform-flow-strip-types": "^6.21.0", | ||
"babel-plugin-transform-metadata": "^2.0.2", | ||
"babel-polyfill": "^6.20.0", | ||
"babel-preset-babili": "0.0.9", | ||
"babel-preset-es2015": "^6.18.0", | ||
"babel-preset-es2015-loose": "^8.0.0", | ||
"babel-preset-react": "^6.16.0", | ||
"babel-preset-stage-0": "^6.16.0", | ||
"eslint-config-airplus": "^2.0.10", | ||
"flow-bin": "^0.35.0", | ||
"flow-bin": "^0.37.4", | ||
"glob": "^7.1.1", | ||
"html-webpack-plugin": "^2.24.1", | ||
"husky": "^0.11.9", | ||
"jsdom": "^9.8.3", | ||
"jss": "^5.5.6", | ||
"jss-camel-case": "^2.0.2", | ||
"mocha": "^3.1.2", | ||
"husky": "^0.12.0", | ||
"inferno": "^0.7.27", | ||
"inferno-component": "^0.7.27", | ||
"inferno-create-element": "^0.7.27", | ||
"inferno-dom": "^0.7.27", | ||
"jsdom": "^9.9.1", | ||
"jss": "^6.1.0", | ||
"jss-camel-case": "^3.0.0", | ||
"mocha": "^3.2.0", | ||
"power-assert": "^1.4.2", | ||
"react": "^15.4.0", | ||
"react-addons-test-utils": "^15.4.0", | ||
"react-dom": "^15.4.0", | ||
"react": "^15.4.1", | ||
"react-addons-test-utils": "^15.4.1", | ||
"react-dom": "^15.4.1", | ||
"sinon": "^1.17.6", | ||
"webpack": "^1.13.3", | ||
"webpack": "^1.14.0", | ||
"webpack-dev-server": "^1.16.2" | ||
}, | ||
"dependencies": { | ||
"derivable": "^0.12.1" | ||
"derivable": "^0.12.1", | ||
"es6-error": "^4.0.0" | ||
} | ||
} |
@@ -7,2 +7,4 @@ # Reactive DI [![Build Status](https://secure.travis-ci.org/zerkalica/reactive-di.png)](http://travis-ci.org/zerkalica/reactive-di) | ||
[todomvc](https://github.com/zerkalica/reactive-di-todomvc) example app. | ||
## About | ||
@@ -9,0 +11,0 @@ |
// @flow | ||
import type { | ||
ComponentFactory, | ||
CreateElement, | ||
SrcComponent, | ||
SetState | ||
} from 'reactive-di/interfaces/component' | ||
import debugName from 'reactive-di/utils/debugName' | ||
import shallowEqual, {shallowStrictEqual} from 'reactive-di/utils/shallowEqual' | ||
import ComponentControllable from 'reactive-di/core/ComponentControllable' | ||
import {DepInfo} from 'reactive-di/core/common' | ||
type ReactComponent<Props, State> = React$Component<*, Props, State> | ||
type ReactComponentClass<Props, State> = Class<ReactComponent<Props, State>> | ||
import type {IHasForceUpdate, ICreateElement, IConsumerFactory, IConsumerListener} from '../atoms/interfaces' | ||
interface StaticContext<Props, State> { | ||
info: DepInfo<SrcComponent<Props, State>, *>; | ||
createElement: CreateElement<*, *>; | ||
interface IReact<Component> { | ||
Component: Component; | ||
createElement: any; | ||
} | ||
// <State: Object, Props: Object> | ||
const ComponentMixin = { | ||
// static __rdiCtx: StaticContext<Props, State> | ||
// setState: (state: State) => void | ||
// state: ?State | ||
// props: Props | ||
// | ||
// _target: SrcComponent<Props, ?State> | ||
// _controllable: IComponentControllable<State, ReactComponentClass<Props, State>> | ||
// _createElement: ReactCreateElement | ||
export default class ReactComponentFactory<Element: React$Element<any>, Component: ReactClass<*>> { | ||
createElement: ICreateElement<Element> | ||
_Component: Function | ||
componentWillMount<Props, State>(): void { | ||
const ctx: StaticContext<Props, State> = this.constructor.__rdiCtx | ||
const t = this | ||
const setState: SetState<State> = (state: State) => { | ||
return t.setState(state) | ||
} | ||
const controllable = this._controllable = new ComponentControllable(ctx.info, setState) | ||
this._createElement = controllable.contextify(ctx.createElement) | ||
constructor(react: IReact<Component>) { | ||
this.createElement = (react.createElement: any) | ||
this.state = controllable.getState() | ||
this._target = ctx.info.target | ||
this._controllable.onWillMount((this: any)) | ||
}, | ||
this._Component = class WrappedComponent<Props> extends react.Component { | ||
static __factory: IConsumerFactory<Props, Element> | ||
componentDidMount() { | ||
this._controllable.onMount() | ||
}, | ||
_consumer: IConsumerListener<Props, Element, Component> | ||
props: Props | ||
componentDidUpdate<Props, State>(_props: Props, _state: State): void { | ||
this._controllable.onUpdate((this: any)) | ||
}, | ||
componentWillMount() { | ||
this._consumer = this.constructor.__factory.create( | ||
(this: IHasForceUpdate<Props>), | ||
this.props | ||
) | ||
} | ||
componentWillUnmount(): void { | ||
this._controllable.onUnmount() | ||
}, | ||
setProps(props: Props): void { | ||
this.props = props | ||
} | ||
shouldComponentUpdate(nextProps: Object, nextState: Object): boolean { | ||
return !shallowEqual(this.props, nextProps) || !shallowStrictEqual(this.state, nextState) | ||
}, | ||
componentDidMount() { | ||
this._consumer.didMount() | ||
} | ||
render(): any { | ||
return this._target(this.props, this.state, this._createElement) | ||
} | ||
} | ||
componentDidUpdate() { | ||
this._consumer.didUpdate() | ||
} | ||
const ComponentDevMixin = { | ||
_showError(e: Error): void { | ||
console.error(e) // eslint-disable-line | ||
}, | ||
componentWillUnmount() { | ||
this._consumer.willUnmount() | ||
} | ||
shouldComponentUpdate(nextProps: Object, nextState: Object): boolean { | ||
return ComponentMixin.shouldComponentUpdate.call(this, nextProps, nextState) | ||
}, | ||
shouldComponentUpdate(nextProps: Props): boolean { | ||
return this._consumer.shouldUpdate(nextProps) | ||
} | ||
componentWillMount(): void { | ||
try { | ||
ComponentMixin.componentWillMount.call(this) | ||
} catch (e) { | ||
this._showError(e) | ||
throw e | ||
render(): Element { | ||
return this._consumer.render() | ||
} | ||
} | ||
}, | ||
componentDidUpdate(): void { | ||
try { | ||
ComponentMixin.componentDidUpdate.call(this) | ||
} catch (e) { | ||
this._showError(e) | ||
throw e | ||
} | ||
}, | ||
componentDidMount(): void { | ||
try { | ||
ComponentMixin.componentDidMount.call(this) | ||
} catch (e) { | ||
this._showError(e) | ||
throw e | ||
} | ||
}, | ||
componentWillUnmount(): void { | ||
try { | ||
ComponentMixin.componentWillUnmount.call(this) | ||
} catch (e) { | ||
this._showError(e) | ||
throw e | ||
} | ||
}, | ||
render(): void { | ||
try { | ||
return ComponentMixin.render.call(this) | ||
} catch (e) { | ||
this._showError(e) | ||
throw e | ||
} | ||
} | ||
} | ||
interface React { | ||
Component: ReactComponentClass<*, *>; | ||
createElement: Function; | ||
} | ||
export default class ReactComponentFactory { | ||
_Component: ReactComponentClass<*, *> | ||
_createElement: CreateElement<*, *> | ||
_mixin: Object | ||
constructor({Component, createElement}: React, isDebug?: boolean) { | ||
this._createElement = (createElement: any) | ||
this._Component = Component | ||
this._mixin = isDebug ? ComponentDevMixin : ComponentMixin | ||
wrapComponent<Props: Object, State: Object>( | ||
factory: IConsumerFactory<Props, Element> | ||
): Component { | ||
return (class WrappedComponent extends (this._Component: any)<Props, State> { | ||
static displayName = factory.displayName | ||
static __factory = factory | ||
}: any) | ||
} | ||
wrapComponent<Props, State>( | ||
info: DepInfo<SrcComponent<Props, State>, *> | ||
): ReactComponentClass<Props, State> { | ||
const createElement = this._createElement | ||
class WrappedComponent extends (this._Component: any)<Props, State> { | ||
static displayName: string = `${debugName(info.target)}` | ||
static __rdiCtx: StaticContext<Props, State> = { | ||
info, | ||
createElement | ||
} | ||
state: State | ||
props: Props | ||
} | ||
Object.assign((WrappedComponent.prototype: Object), this._mixin) | ||
return WrappedComponent | ||
} | ||
} | ||
if (0) ((new ReactComponentFactory(...(0: any))): ComponentFactory) // eslint-disable-line |
// @flow | ||
import CustomReflect from 'reactive-di/CustomReflect' | ||
import { | ||
paramTypesKey, | ||
metaKey, | ||
subtypeKey, | ||
lcKey, | ||
ComponentMeta, | ||
ThemeMeta, | ||
SourceMeta, | ||
StatusMeta, | ||
ServiceMeta, | ||
AbstractMeta | ||
} from 'reactive-di/core/common' | ||
import type {ArgDep, LifeCycle} from 'reactive-di/interfaces/deps' // eslint-disable-line | ||
import Updater from 'reactive-di/core/Updater' | ||
import type {ComponentMetaRec, SourceMetaRec} from 'reactive-di/core/common' | ||
import type {IKey, IDepRegister, IRawArg} from './atoms/interfaces' | ||
import GenericThemeHook from './theme/GenericThemeHook' | ||
const dm = CustomReflect.defineMetadata | ||
/* eslint-disable no-param-reassign */ | ||
export function deps<V: Function>(...args: ArgDep[]): (target: V) => V { | ||
export interface SourceMetaRec { | ||
key: string; | ||
loaded?: boolean; | ||
} | ||
export interface ComponentMetaRec { | ||
register?: IDepRegister[]; | ||
onError?: IKey; | ||
} | ||
export function deps<V: Function>(...args: IRawArg[]): (target: V) => V { | ||
return (target: V) => { | ||
if (args.length) { | ||
dm(paramTypesKey, args, target) | ||
target._rdiArgs = args | ||
} | ||
@@ -31,4 +27,5 @@ return target | ||
export function factory<V: Function>(target: V, isJsx?: boolean): V { | ||
dm(subtypeKey, isJsx ? 'jsx' : 'func', target) | ||
export function factory<V: Function>(target: V): V { | ||
target._rdiFn = true | ||
return target | ||
@@ -39,4 +36,4 @@ } | ||
return (target: V) => { | ||
dm(metaKey, new ComponentMeta(rec || {}), target) | ||
dm(subtypeKey, 'jsx', target) | ||
target._rdiJsx = true | ||
target._rdiCmp = rec | ||
return target | ||
@@ -47,9 +44,11 @@ } | ||
export function theme<V: Function>(target: V): V { | ||
dm(metaKey, new ThemeMeta(), target) | ||
target._rdiHook = GenericThemeHook | ||
return target | ||
} | ||
export function source<R, V: Class<R>>(rec: SourceMetaRec): (target: V) => V { | ||
export function source<V: Function>(rec: SourceMetaRec): (target: V) => V { | ||
return (target: V) => { | ||
dm(metaKey, new SourceMeta(rec), target) | ||
target._rdiKey = rec.key | ||
target._rdiInst = rec.instance || false | ||
target._rdiLoaded = rec.loaded || false | ||
return target | ||
@@ -59,11 +58,4 @@ } | ||
export function updaters<V: Function>(...items: Class<Updater>[]): (target: V) => V { | ||
return (target: V) => { | ||
dm(metaKey, new StatusMeta(items), target) | ||
return target | ||
} | ||
} | ||
export function service<V: Function>(target: V): V { | ||
dm(metaKey, new ServiceMeta(), target) | ||
export function actions<V: Function>(target: V): V { | ||
target._rdiEnd = true | ||
return target | ||
@@ -73,10 +65,11 @@ } | ||
export function abstract<V: Function>(target: V): V { | ||
dm(metaKey, new AbstractMeta(), target) | ||
target._rdiAbs = true | ||
return target | ||
} | ||
export function hooks<V: Function>(target: V): (lc: Class<LifeCycle<*>>) => Class<LifeCycle<*>> { | ||
return (lc: Class<LifeCycle<*>>) => { | ||
dm(lcKey, lc, target) | ||
dm(metaKey, new ServiceMeta(), lc) | ||
export function hooks<V1: Function, V2: Function>(target: V1): (lc: V2) => V2 { | ||
return (lc: V2) => { | ||
target._rdiHook = lc | ||
lc._rdiEnd = true | ||
return lc | ||
@@ -89,4 +82,4 @@ } | ||
export function cloneComponent<C: Function>(src: C, rec?: ComponentMetaRec): C { | ||
function target(arg1: any, arg2: any, arg3: any) { | ||
return src(arg1, arg2, arg3) | ||
function target(arg1: any, arg2: any) { | ||
return src(arg1, arg2) | ||
} | ||
@@ -96,4 +89,5 @@ target.displayName = (src.displayName || src.name) + '#clone-' + (cloneNumber || '0') | ||
Object.setPrototypeOf(target, src) | ||
target._rdiJsx = true | ||
if (rec) { | ||
dm(metaKey, new ComponentMeta(rec), target) | ||
target._rdiCmp = rec | ||
} | ||
@@ -100,0 +94,0 @@ |
// @flow | ||
import Di from 'reactive-di/core/Di' | ||
import {isComponent} from 'reactive-di/core/common' | ||
import ReactComponentFactory from 'reactive-di/adapters/ReactComponentFactory' | ||
import BaseModel from 'reactive-di/utils/BaseModel' | ||
import Updater, {UpdaterStatus} from 'reactive-di/core/Updater' | ||
import bindObservableToAtom from 'reactive-di/utils/bindObservableToAtom' | ||
import DiFactory from './DiFactory' | ||
export type { | ||
ArgsInfo, | ||
Middleware | ||
} from 'reactive-di/utils/MiddlewareFactory' | ||
import IndexCollection from './utils/IndexCollection' | ||
import refsSetter from './utils/refsSetter' | ||
import Updater, {RecoverableError} from './utils/Updater' | ||
import BaseModel from './utils/BaseModel' | ||
import debugName from './utils/debugName' | ||
import {setter, eventSetter} from './utils/wrapObject' | ||
export type { | ||
RegisterDepItem, | ||
Key, | ||
ResultOf, | ||
LifeCycle | ||
} from 'reactive-di/interfaces/deps' | ||
import SourceStatus from './atoms/SourceStatus' | ||
import ReactComponentFactory from './adapters/ReactComponentFactory' | ||
export { | ||
ReactComponentFactory, | ||
SourceStatus, | ||
debugName, | ||
setter, | ||
eventSetter, | ||
refsSetter, | ||
BaseModel, | ||
Updater, | ||
RecoverableError, | ||
IndexCollection, | ||
DiFactory | ||
} | ||
export type { | ||
Atom | ||
} from 'reactive-di/interfaces/atom' | ||
ICallerInfo, | ||
IHasForceUpdate, | ||
ISettable, | ||
IBaseHook, | ||
IConsumerHook, | ||
IDepRegister, | ||
IRawArg, | ||
IErrorHandler, | ||
IMiddlewares, | ||
IDepInfo | ||
} from './atoms/interfaces' | ||
export { | ||
AbstractSheetFactory | ||
} from './theme/interfaces' | ||
export type { | ||
SrcComponent, | ||
StyleSheet, | ||
SheetFactory, | ||
CssObj, | ||
RawStyleSheet, | ||
ComponentFactory, | ||
CreateStyleSheet, | ||
IComponentControllable | ||
} from 'reactive-di/interfaces/component' | ||
export type { | ||
MultiUpdate, | ||
SingleUpdate | ||
} from 'reactive-di/interfaces/updater' | ||
export { | ||
Di, | ||
isComponent, | ||
Updater, | ||
UpdaterStatus, | ||
BaseModel, | ||
ReactComponentFactory, | ||
bindObservableToAtom | ||
} | ||
StyleSheet | ||
} from './theme/interfaces' |
// @flow | ||
export default class BaseModel<Rec: Object> { | ||
static defaults: Rec | ||
import {setterKey} from '../atoms/interfaces' | ||
constructor(rec?: Rec) { | ||
Object.assign(this, this.constructor.defaults, rec) | ||
export type SetterResult<V: Object> = { | ||
(v: $Shape<$Subtype<V>>): void; | ||
[id: $Keys<V>]: (v: mixed) => void; | ||
} | ||
export default class BaseModel { | ||
copy(rec: Object): this { | ||
return Object.assign((Object.create(this.constructor.prototype): any), this, rec) | ||
} | ||
copy(rec: Rec): any { | ||
return new this.constructor({...this, ...rec}) | ||
set(rec: Object): this { | ||
const val = this.copy(rec) | ||
;(this: any)[setterKey].set(val) | ||
return val | ||
} | ||
reset(): this { | ||
const val = new this.constructor() | ||
;(this: any)[setterKey].set(val) | ||
return val | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
349057
642
2
35
95
4810
1
+ Addedes6-error@^4.0.0
+ Addedes6-error@4.1.1(transitive)