@beef-flux/store
Advanced tools
Comparing version 0.0.2 to 0.1.0
import * as React from 'react'; | ||
import { Manager } from './context'; | ||
export interface StateHistory<T> { | ||
@@ -58,36 +59,14 @@ actionName: string; | ||
constructor(); | ||
static bind(storeName: string): any; | ||
static bindTo<S, P extends { | ||
static subscribe<C, T>(onUpdate: (componentState: C, nextStoreState: T, oldStoreState: T) => Partial<C>): any; | ||
static subscribeTo<C, T, P extends { | ||
new (...args: any[]): {}; | ||
}>(storeName: string, constructor: P): { | ||
new (props: any): { | ||
render(): React.ComponentElement<{ | ||
children?: React.ReactNode; | ||
}, React.Component<{ | ||
children?: React.ReactNode; | ||
}, any, any>>; | ||
context: any; | ||
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<{}>) => {} | Pick<{}, K>) | Pick<{}, K>, callback?: () => void): void; | ||
forceUpdate(callBack?: () => void): void; | ||
readonly props: Readonly<{ | ||
children?: React.ReactNode; | ||
}> & Readonly<{}>; | ||
state: Readonly<{}>; | ||
refs: { | ||
[key: string]: React.ReactInstance; | ||
}; | ||
componentDidMount?(): void; | ||
shouldComponentUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): boolean; | ||
componentWillUnmount?(): void; | ||
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>): any; | ||
componentDidUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>, snapshot?: any): void; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void; | ||
}>(onUpdate: (componentState: C, nextStoreState: T, oldStoreState: T) => Partial<C>, constructor: P): { | ||
new (args: any): { | ||
[x: string]: any; | ||
__listeners: number[]; | ||
componentDidMount(): void; | ||
componentWillUnmount(): void; | ||
}; | ||
contextType: React.Context<import("./context").Manager>; | ||
[x: string]: any; | ||
contextType: React.Context<Manager>; | ||
}; | ||
@@ -94,0 +73,0 @@ static Config(config: Partial<StoreConfig>): <P extends new (...args: any[]) => {}>(constructor: P) => { |
@@ -15,15 +15,3 @@ "use strict"; | ||
})(); | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var React = require("react"); | ||
var extend = require("extend"); | ||
@@ -89,20 +77,35 @@ var assign = require("lodash/assign"); | ||
} | ||
Store.bind = function (storeName) { | ||
return Store.bindTo.bind(this, storeName); | ||
Store.subscribe = function (onUpdate) { | ||
return Store.subscribeTo.bind(this, onUpdate); | ||
}; | ||
Store.bindTo = function (storeName, constructor) { | ||
Store.subscribeTo = function (onUpdate, constructor) { | ||
var _a; | ||
var storeType = this; | ||
var storeName = this['name']; | ||
var construct = constructor; | ||
return _a = /** @class */ (function (_super) { | ||
__extends(class_1, _super); | ||
function class_1(props) { | ||
return _super.call(this, props) || this; | ||
function class_1(args) { | ||
var _this = _super.call(this, args) || this; | ||
_this.__listeners = []; | ||
var props = args; | ||
var store = props._manager.getStore(storeName, storeType); | ||
_this.state = onUpdate(_this.state ? _this.state : {}, store.getState(), {}); | ||
return _this; | ||
} | ||
class_1.prototype.render = function () { | ||
var _a; | ||
var store = this.context.getStore(storeName, storeType); | ||
return React.createElement(constructor, __assign((_a = {}, _a[storeName] = store, _a), this.props), null); | ||
class_1.prototype.componentDidMount = function () { | ||
var _this = this; | ||
_super.prototype['componentDidMount'] ? _super.prototype['componentDidMount'].call(this) : null; | ||
var store = this.props._manager.getStore(storeName, storeType); | ||
this.__listeners.push(store.listen(function (nextState, oldState) { return _this.setState(onUpdate(_this.state, nextState, oldState)); })); | ||
}; | ||
class_1.prototype.componentWillUnmount = function () { | ||
//super.componentWillUnmount() | ||
var store = this.props._manager.getStore(storeName, storeType); | ||
this.__listeners.forEach(function (index) { | ||
store.ignore(index); | ||
}); | ||
}; | ||
return class_1; | ||
}(React.Component)), | ||
}(construct)), | ||
_a.contextType = context_1.default, | ||
@@ -109,0 +112,0 @@ _a; |
@@ -53,3 +53,3 @@ import moment = require("moment"); | ||
static double(config?: BaseConfig<number> & NumberConfig): any; | ||
static array<T>(config?: BaseConfig<T[]> & ArrayConfig<T> & Partial<ObjectConfig<T>>): any; | ||
static array<T>(config?: BaseConfig<T[]> & ArrayConfig<T> & ObjectConfig<T>): any; | ||
static object<T>(config?: BaseConfig<T> & ObjectConfig<T>): any; | ||
@@ -56,0 +56,0 @@ static datetime(config?: BaseConfig<moment.Moment> & DateConfig): any; |
@@ -7,2 +7,3 @@ /// <reference types="react" /> | ||
import { Manager as ContextManager } from './context'; | ||
import Schema from './decorators/schema-decorator'; | ||
declare const _default: { | ||
@@ -12,9 +13,7 @@ Actions: typeof Actions; | ||
BaseStore: typeof Store; | ||
decorators: { | ||
Schema: typeof import("./decorators/schema-decorator").default; | ||
}; | ||
Context: import("react").Context<ContextManager>; | ||
subscribe: (storeMap: SubscribeMap) => any; | ||
Wrap: (Component: typeof import("react").Component) => (props: any) => JSX.Element; | ||
}; | ||
export default _default; | ||
export { ActionsManager, SubscribeMap, ContextManager }; | ||
export { ActionsManager, SubscribeMap, ContextManager, Schema }; |
@@ -7,6 +7,8 @@ "use strict"; | ||
var base_store_1 = require("./base-store"); | ||
var decorators_1 = require("./decorators"); | ||
var subscribe_1 = require("./subscribe"); | ||
var context_1 = require("./context"); | ||
exports.ContextManager = context_1.Manager; | ||
var schema_decorator_1 = require("./decorators/schema-decorator"); | ||
exports.Schema = schema_decorator_1.default; | ||
var wrapper_1 = require("./context/wrapper"); | ||
exports.default = { | ||
@@ -16,5 +18,5 @@ Actions: actions_1.default, | ||
BaseStore: base_store_1.default, | ||
decorators: decorators_1.default, | ||
Context: context_1.default, | ||
subscribe: subscribe_1.default, | ||
Wrap: wrapper_1.default | ||
}; |
{ | ||
"name": "@beef-flux/store", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Flux compatible state machine", | ||
@@ -33,3 +33,4 @@ "keywords": [ | ||
"react": "^16.7.0" | ||
} | ||
}, | ||
"gitHead": "9833b3b5800857e8128397c0819a6d28f56fb4b7" | ||
} |
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
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
56274
26
1569