Comparing version 1.0.0-1531951520682 to 1.0.0-1532013016694
@@ -6,21 +6,18 @@ import * as React from 'react'; | ||
export declare type TConnect<State = {}, Actions = {}> = { | ||
appState: State; | ||
actions: Actions; | ||
app: { | ||
state: State; | ||
actions: Actions; | ||
}; | ||
}; | ||
declare type Omit<T, K extends keyof T> = Pick<T, ({ | ||
[P in keyof T]: P; | ||
} & { | ||
[P in K]: never; | ||
} & { | ||
[x: string]: never; | ||
[x: number]: never; | ||
})[keyof T]>; | ||
export default class ReactApp<State extends object, Providers extends object, Actions extends { | ||
[namespace: string]: ActionsCallback<Providers, State>; | ||
} | ActionsCallback<Providers, State>> extends App<State, Providers, Actions> { | ||
connect<Props, ConnectedActions = Actions extends { | ||
connect: <Props, ConnectedActions = Actions extends { | ||
[namespace: string]: ActionsCallback<Providers, State>; | ||
} ? { | ||
[Namespace in keyof Actions]: ReturnType<Actions[Namespace]>; | ||
} : Actions extends ActionsCallback<Providers, State> ? ReturnType<Actions> : any>(Component: IReactComponent<Props & TConnect<State, ConnectedActions>>): IReactComponent<Omit<Props & TConnect<State, ConnectedActions>, keyof TConnect<State, ConnectedActions>>>; | ||
} ? { [Namespace in keyof Actions]: ReturnType<Actions[Namespace]>; } : Actions extends ActionsCallback<Providers, State> ? ReturnType<Actions> : any>(Component: IReactComponent<Props & TConnect<State, ConnectedActions>>) => IReactComponent<Pick<Props & TConnect<State, ConnectedActions>, ({ [P in keyof (Props & TConnect<State, ConnectedActions>)]: P; } & { | ||
app: never; | ||
} & { | ||
[x: string]: never; | ||
[x: number]: never; | ||
})["app" | keyof Props]>>; | ||
} |
@@ -5,65 +5,92 @@ import * as React from 'react'; | ||
export default class ReactApp extends App { | ||
connect(Component) { | ||
const componentId = nextComponentId++; | ||
let componentInstanceId = 0; | ||
const instance = this; | ||
const isClassComponent = Component.prototype && typeof Component.prototype.render === 'function'; | ||
if (isClassComponent) { | ||
const originalRender = Component.prototype.render; | ||
const originalWillUnmount = Component.prototype.componentWillUnmount; | ||
Component.prototype.componentWillUnmount = function () { | ||
if (this.__mutationListener) { | ||
constructor() { | ||
super(...arguments); | ||
this.connect = (Component) => { | ||
const componentId = nextComponentId++; | ||
let componentInstanceId = 0; | ||
const instance = this; | ||
const isClassComponent = Component.prototype && typeof Component.prototype.render === 'function'; | ||
if (isClassComponent) { | ||
const originalRender = Component.prototype.render; | ||
const originalWillUnmount = Component.prototype.componentWillUnmount; | ||
Component.prototype.componentWillUnmount = function () { | ||
if (this.__mutationListener) { | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:remove', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.props.app.__componentInstanceId, | ||
name: Component.name || '', | ||
}, | ||
}); | ||
} | ||
this.__mutationListener.dispose(); | ||
} | ||
originalWillUnmount && originalWillUnmount.call(this); | ||
}; | ||
Component.prototype.render = function () { | ||
const trackId = instance.trackState(); | ||
const value = originalRender.call(this); | ||
const paths = instance.clearTrackState(trackId); | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:remove', | ||
type: this.__mutationListener | ||
? 'component:update' | ||
: 'component:add', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.props.__componentInstanceId, | ||
componentInstanceId: this.props.app.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
}, | ||
}); | ||
} | ||
this.__mutationListener.dispose(); | ||
if (this.__mutationListener) { | ||
this.__mutationListener.update(paths); | ||
} | ||
else { | ||
this.__mutationListener = instance.addMutationListener(paths, () => { | ||
this.forceUpdate(); | ||
}); | ||
} | ||
return value; | ||
}; | ||
} | ||
return class extends React.PureComponent { | ||
constructor() { | ||
super(...arguments); | ||
this.__componentId = componentId; | ||
this.__componentInstanceId = componentInstanceId++; | ||
} | ||
originalWillUnmount && originalWillUnmount.call(this); | ||
}; | ||
Component.prototype.render = function () { | ||
const trackId = instance.trackState(); | ||
const value = originalRender.call(this); | ||
const paths = instance.clearTrackState(trackId); | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: this.__mutationListener | ||
? 'component:update' | ||
: 'component:add', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.props.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
componentWillUnmount() { | ||
if (this.__mutationListener) { | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:remove', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.__componentInstanceId, | ||
name: Component.name || '', | ||
}, | ||
}); | ||
} | ||
this.__mutationListener.dispose(); | ||
} | ||
} | ||
renderStatelessComponent() { | ||
const trackId = instance.trackState(); | ||
const value = Component(Object.assign({}, this.props, { | ||
app: { | ||
state: instance.state, | ||
actions: instance.actions, | ||
__componentInstanceId: this.__componentInstanceId, | ||
}, | ||
}); | ||
} | ||
if (this.__mutationListener) { | ||
this.__mutationListener.update(paths); | ||
} | ||
else { | ||
this.__mutationListener = instance.addMutationListener(paths, () => { | ||
this.forceUpdate(); | ||
}); | ||
} | ||
return value; | ||
}; | ||
} | ||
return class extends React.PureComponent { | ||
constructor() { | ||
super(...arguments); | ||
this.__componentId = componentId; | ||
this.__componentInstanceId = componentInstanceId++; | ||
} | ||
componentWillUnmount() { | ||
if (this.__mutationListener) { | ||
}), this.context); | ||
const paths = instance.clearTrackState(trackId); | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:remove', | ||
type: this.__mutationListener | ||
? 'component:update' | ||
: 'component:add', | ||
data: { | ||
@@ -73,52 +100,32 @@ componentId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
}, | ||
}); | ||
} | ||
this.__mutationListener.dispose(); | ||
if (this.__mutationListener) { | ||
this.__mutationListener.update(paths); | ||
} | ||
else { | ||
this.__mutationListener = instance.addMutationListener(paths, () => { | ||
this.forceUpdate(); | ||
}); | ||
} | ||
return value; | ||
} | ||
} | ||
renderStatelessComponent() { | ||
const trackId = instance.trackState(); | ||
const value = Component(Object.assign({}, this.props, { | ||
appState: instance.state, | ||
actions: instance.actions, | ||
__componentInstanceId: this.__componentInstanceId, | ||
}), this.context); | ||
const paths = instance.clearTrackState(trackId); | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: this.__mutationListener | ||
? 'component:update' | ||
: 'component:add', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
renderClassComponent() { | ||
return React.createElement(Component, Object.assign({}, this.props, { | ||
app: { | ||
state: instance.state, | ||
actions: instance.actions, | ||
__componentInstanceId: this.__componentInstanceId, | ||
}, | ||
}); | ||
})); | ||
} | ||
if (this.__mutationListener) { | ||
this.__mutationListener.update(paths); | ||
render() { | ||
if (isClassComponent) { | ||
return this.renderClassComponent(); | ||
} | ||
return this.renderStatelessComponent(); | ||
} | ||
else { | ||
this.__mutationListener = instance.addMutationListener(paths, () => { | ||
this.forceUpdate(); | ||
}); | ||
} | ||
return value; | ||
} | ||
renderClassComponent() { | ||
return React.createElement(Component, Object.assign({}, this.props, { | ||
appState: instance.state, | ||
actions: instance.actions, | ||
__componentInstanceId: this.__componentInstanceId, | ||
})); | ||
} | ||
render() { | ||
if (isClassComponent) { | ||
return this.renderClassComponent(); | ||
} | ||
return this.renderStatelessComponent(); | ||
} | ||
}; | ||
}; | ||
@@ -125,0 +132,0 @@ } |
@@ -18,5 +18,5 @@ import * as React from 'react'; | ||
}); | ||
const Component = ({ appState, actions }) => { | ||
actions.doThis(); | ||
return React.createElement("h1", null, appState.foo); | ||
const Component = ({ app }) => { | ||
app.actions.doThis(); | ||
return React.createElement("h1", null, app.state.foo); | ||
}; | ||
@@ -43,5 +43,5 @@ const ConnectedComponent = app.connect(Component); | ||
render() { | ||
const { actions, appState } = this.props; | ||
actions.doThis(); | ||
return React.createElement("h1", null, appState.foo); | ||
const { app } = this.props; | ||
app.actions.doThis(); | ||
return React.createElement("h1", null, app.state.foo); | ||
} | ||
@@ -48,0 +48,0 @@ } |
@@ -6,21 +6,18 @@ import * as React from 'react'; | ||
export declare type TConnect<State = {}, Actions = {}> = { | ||
appState: State; | ||
actions: Actions; | ||
app: { | ||
state: State; | ||
actions: Actions; | ||
}; | ||
}; | ||
declare type Omit<T, K extends keyof T> = Pick<T, ({ | ||
[P in keyof T]: P; | ||
} & { | ||
[P in K]: never; | ||
} & { | ||
[x: string]: never; | ||
[x: number]: never; | ||
})[keyof T]>; | ||
export default class ReactApp<State extends object, Providers extends object, Actions extends { | ||
[namespace: string]: ActionsCallback<Providers, State>; | ||
} | ActionsCallback<Providers, State>> extends App<State, Providers, Actions> { | ||
connect<Props, ConnectedActions = Actions extends { | ||
connect: <Props, ConnectedActions = Actions extends { | ||
[namespace: string]: ActionsCallback<Providers, State>; | ||
} ? { | ||
[Namespace in keyof Actions]: ReturnType<Actions[Namespace]>; | ||
} : Actions extends ActionsCallback<Providers, State> ? ReturnType<Actions> : any>(Component: IReactComponent<Props & TConnect<State, ConnectedActions>>): IReactComponent<Omit<Props & TConnect<State, ConnectedActions>, keyof TConnect<State, ConnectedActions>>>; | ||
} ? { [Namespace in keyof Actions]: ReturnType<Actions[Namespace]>; } : Actions extends ActionsCallback<Providers, State> ? ReturnType<Actions> : any>(Component: IReactComponent<Props & TConnect<State, ConnectedActions>>) => IReactComponent<Pick<Props & TConnect<State, ConnectedActions>, ({ [P in keyof (Props & TConnect<State, ConnectedActions>)]: P; } & { | ||
app: never; | ||
} & { | ||
[x: string]: never; | ||
[x: number]: never; | ||
})["app" | keyof Props]>>; | ||
} |
@@ -7,65 +7,92 @@ "use strict"; | ||
class ReactApp extends __1.default { | ||
connect(Component) { | ||
const componentId = nextComponentId++; | ||
let componentInstanceId = 0; | ||
const instance = this; | ||
const isClassComponent = Component.prototype && typeof Component.prototype.render === 'function'; | ||
if (isClassComponent) { | ||
const originalRender = Component.prototype.render; | ||
const originalWillUnmount = Component.prototype.componentWillUnmount; | ||
Component.prototype.componentWillUnmount = function () { | ||
if (this.__mutationListener) { | ||
constructor() { | ||
super(...arguments); | ||
this.connect = (Component) => { | ||
const componentId = nextComponentId++; | ||
let componentInstanceId = 0; | ||
const instance = this; | ||
const isClassComponent = Component.prototype && typeof Component.prototype.render === 'function'; | ||
if (isClassComponent) { | ||
const originalRender = Component.prototype.render; | ||
const originalWillUnmount = Component.prototype.componentWillUnmount; | ||
Component.prototype.componentWillUnmount = function () { | ||
if (this.__mutationListener) { | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:remove', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.props.app.__componentInstanceId, | ||
name: Component.name || '', | ||
}, | ||
}); | ||
} | ||
this.__mutationListener.dispose(); | ||
} | ||
originalWillUnmount && originalWillUnmount.call(this); | ||
}; | ||
Component.prototype.render = function () { | ||
const trackId = instance.trackState(); | ||
const value = originalRender.call(this); | ||
const paths = instance.clearTrackState(trackId); | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:remove', | ||
type: this.__mutationListener | ||
? 'component:update' | ||
: 'component:add', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.props.__componentInstanceId, | ||
componentInstanceId: this.props.app.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
}, | ||
}); | ||
} | ||
this.__mutationListener.dispose(); | ||
if (this.__mutationListener) { | ||
this.__mutationListener.update(paths); | ||
} | ||
else { | ||
this.__mutationListener = instance.addMutationListener(paths, () => { | ||
this.forceUpdate(); | ||
}); | ||
} | ||
return value; | ||
}; | ||
} | ||
return class extends React.PureComponent { | ||
constructor() { | ||
super(...arguments); | ||
this.__componentId = componentId; | ||
this.__componentInstanceId = componentInstanceId++; | ||
} | ||
originalWillUnmount && originalWillUnmount.call(this); | ||
}; | ||
Component.prototype.render = function () { | ||
const trackId = instance.trackState(); | ||
const value = originalRender.call(this); | ||
const paths = instance.clearTrackState(trackId); | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: this.__mutationListener | ||
? 'component:update' | ||
: 'component:add', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.props.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
componentWillUnmount() { | ||
if (this.__mutationListener) { | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:remove', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.__componentInstanceId, | ||
name: Component.name || '', | ||
}, | ||
}); | ||
} | ||
this.__mutationListener.dispose(); | ||
} | ||
} | ||
renderStatelessComponent() { | ||
const trackId = instance.trackState(); | ||
const value = Component(Object.assign({}, this.props, { | ||
app: { | ||
state: instance.state, | ||
actions: instance.actions, | ||
__componentInstanceId: this.__componentInstanceId, | ||
}, | ||
}); | ||
} | ||
if (this.__mutationListener) { | ||
this.__mutationListener.update(paths); | ||
} | ||
else { | ||
this.__mutationListener = instance.addMutationListener(paths, () => { | ||
this.forceUpdate(); | ||
}); | ||
} | ||
return value; | ||
}; | ||
} | ||
return class extends React.PureComponent { | ||
constructor() { | ||
super(...arguments); | ||
this.__componentId = componentId; | ||
this.__componentInstanceId = componentInstanceId++; | ||
} | ||
componentWillUnmount() { | ||
if (this.__mutationListener) { | ||
}), this.context); | ||
const paths = instance.clearTrackState(trackId); | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:remove', | ||
type: this.__mutationListener | ||
? 'component:update' | ||
: 'component:add', | ||
data: { | ||
@@ -75,52 +102,32 @@ componentId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
}, | ||
}); | ||
} | ||
this.__mutationListener.dispose(); | ||
if (this.__mutationListener) { | ||
this.__mutationListener.update(paths); | ||
} | ||
else { | ||
this.__mutationListener = instance.addMutationListener(paths, () => { | ||
this.forceUpdate(); | ||
}); | ||
} | ||
return value; | ||
} | ||
} | ||
renderStatelessComponent() { | ||
const trackId = instance.trackState(); | ||
const value = Component(Object.assign({}, this.props, { | ||
appState: instance.state, | ||
actions: instance.actions, | ||
__componentInstanceId: this.__componentInstanceId, | ||
}), this.context); | ||
const paths = instance.clearTrackState(trackId); | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: this.__mutationListener | ||
? 'component:update' | ||
: 'component:add', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
renderClassComponent() { | ||
return React.createElement(Component, Object.assign({}, this.props, { | ||
app: { | ||
state: instance.state, | ||
actions: instance.actions, | ||
__componentInstanceId: this.__componentInstanceId, | ||
}, | ||
}); | ||
})); | ||
} | ||
if (this.__mutationListener) { | ||
this.__mutationListener.update(paths); | ||
render() { | ||
if (isClassComponent) { | ||
return this.renderClassComponent(); | ||
} | ||
return this.renderStatelessComponent(); | ||
} | ||
else { | ||
this.__mutationListener = instance.addMutationListener(paths, () => { | ||
this.forceUpdate(); | ||
}); | ||
} | ||
return value; | ||
} | ||
renderClassComponent() { | ||
return React.createElement(Component, Object.assign({}, this.props, { | ||
appState: instance.state, | ||
actions: instance.actions, | ||
__componentInstanceId: this.__componentInstanceId, | ||
})); | ||
} | ||
render() { | ||
if (isClassComponent) { | ||
return this.renderClassComponent(); | ||
} | ||
return this.renderStatelessComponent(); | ||
} | ||
}; | ||
}; | ||
@@ -127,0 +134,0 @@ } |
@@ -20,5 +20,5 @@ "use strict"; | ||
}); | ||
const Component = ({ appState, actions }) => { | ||
actions.doThis(); | ||
return React.createElement("h1", null, appState.foo); | ||
const Component = ({ app }) => { | ||
app.actions.doThis(); | ||
return React.createElement("h1", null, app.state.foo); | ||
}; | ||
@@ -45,5 +45,5 @@ const ConnectedComponent = app.connect(Component); | ||
render() { | ||
const { actions, appState } = this.props; | ||
actions.doThis(); | ||
return React.createElement("h1", null, appState.foo); | ||
const { app } = this.props; | ||
app.actions.doThis(); | ||
return React.createElement("h1", null, app.state.foo); | ||
} | ||
@@ -50,0 +50,0 @@ } |
{ | ||
"name": "overmind", | ||
"version": "1.0.0-1531951520682", | ||
"version": "1.0.0-1532013016694", | ||
"description": "Functional actions", | ||
@@ -36,5 +36,5 @@ "author": "Christian Alfoni <christianalfoni@gmail.com>", | ||
"@types/node": "^10.5.1", | ||
"action-chain": "1.0.0-1531951520682", | ||
"action-chain": "1.0.0-1532013016694", | ||
"is-plain-object": "^2.0.4", | ||
"proxy-state-tree": "1.0.0-1531951520682", | ||
"proxy-state-tree": "1.0.0-1532013016694", | ||
"tslib": "^1.9.3" | ||
@@ -41,0 +41,0 @@ }, |
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
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
197730
1744
+ Addedaction-chain@1.0.0-1532013016694(transitive)
+ Addedproxy-state-tree@1.0.0-1532013016694(transitive)
- Removedaction-chain@1.0.0-1531951520682(transitive)
- Removedproxy-state-tree@1.0.0-1531951520682(transitive)