refract-xstream
Advanced tools
Comparing version 2.2.0 to 3.0.0
255
index.es.js
import xs from 'xstream'; | ||
import dropRepeats from 'xstream/extra/dropRepeats'; | ||
import $$observable from 'symbol-observable'; | ||
import { isValidElement, createElement, Component } from 'react'; | ||
import { useState, useLayoutEffect, useEffect, isValidElement, createElement, Component } from 'react'; | ||
@@ -41,2 +41,3 @@ /*! ***************************************************************************** | ||
var PROPS_EFFECT = '@@refract/effect/props'; | ||
var COMPONENT_EFFECT = '@@refract/effect/component'; | ||
var toProps = function (props) { return ({ | ||
@@ -56,2 +57,6 @@ type: PROPS_EFFECT, | ||
}); }; | ||
var toRender = function (data) { return ({ | ||
type: COMPONENT_EFFECT, | ||
payload: data | ||
}); }; | ||
@@ -106,8 +111,5 @@ var MOUNT_EVENT = '@@refract/event/mount'; | ||
}; | ||
var createComponent = function (instance, dataObservable, pushEvent) { | ||
var data = function () { return xs.from(dataObservable); }; | ||
var getComponentBase = function (data, pushEvent) { | ||
var fromEvent = function (eventName, valueTransformer) { | ||
return data() | ||
.filter(isEvent(eventName)) | ||
.map(function (data) { | ||
return data.filter(isEvent(eventName)).map(function (data) { | ||
var value = data.payload.value; | ||
@@ -118,33 +120,4 @@ return valueTransformer ? valueTransformer(value) : value; | ||
return { | ||
mount: data() | ||
.filter(isEvent(MOUNT_EVENT)) | ||
.mapTo(undefined), | ||
unmount: data() | ||
.filter(isEvent(UNMOUNT_EVENT)) | ||
.mapTo(undefined), | ||
observe: function (propName, valueTransformer) { | ||
if (propName && typeof instance.props[propName] === 'function') { | ||
return data() | ||
.filter(isCallback(propName)) | ||
.map(function (data) { | ||
var args = data.payload.args; | ||
return valueTransformer | ||
? valueTransformer(args) | ||
: args[0]; | ||
}); | ||
} | ||
if (propName) { | ||
return data() | ||
.filter(isProps) | ||
.map(function (data) { | ||
var prop = data.payload[propName]; | ||
return valueTransformer ? valueTransformer(prop) : prop; | ||
}) | ||
.compose(dropRepeats()); | ||
} | ||
return data() | ||
.filter(isProps) | ||
.map(function (data) { return data.payload; }) | ||
.compose(dropRepeats(shallowEquals)); | ||
}, | ||
mount: data.filter(isEvent(MOUNT_EVENT)).mapTo(undefined), | ||
unmount: data.filter(isEvent(UNMOUNT_EVENT)).mapTo(undefined), | ||
fromEvent: fromEvent, | ||
@@ -164,4 +137,33 @@ pushEvent: pushEvent, | ||
}; | ||
var getObserve = function (getProp, data) { | ||
return function observe(propName, valueTransformer) { | ||
if (propName && typeof getProp(propName) === 'function') { | ||
return data() | ||
.filter(isCallback(propName)) | ||
.map(function (data) { | ||
var args = data.payload.args; | ||
return valueTransformer ? valueTransformer(args) : args[0]; | ||
}); | ||
} | ||
if (propName) { | ||
return data() | ||
.filter(isProps) | ||
.map(function (data) { | ||
var prop = data.payload[propName]; | ||
return valueTransformer ? valueTransformer(prop) : prop; | ||
}) | ||
.compose(dropRepeats()); | ||
} | ||
return data() | ||
.filter(isProps) | ||
.map(function (data) { return data.payload; }) | ||
.compose(dropRepeats(shallowEquals)); | ||
}; | ||
}; | ||
var createComponent = function (getProp, dataObservable, pushEvent) { | ||
var data = function () { return xs.from(dataObservable); }; | ||
return __assign({ observe: getObserve(getProp, data) }, getComponentBase(data(), pushEvent)); | ||
}; | ||
var configureComponent = function (handler, errorHandler) { return function (aperture, instance, isValidElement$$1, isComponentClass) { | ||
var configureComponent = function (aperture, instance, isValidElement$$1, isComponentClass, handler, errorHandler) { | ||
if (isValidElement$$1 === void 0) { isValidElement$$1 = function () { return false; }; } | ||
@@ -186,3 +188,5 @@ if (isComponentClass === void 0) { isComponentClass = function () { return false; }; } | ||
var finalHandler = function (initialProps, initialContext) { | ||
var effectHandler = handler(initialProps, initialContext); | ||
var effectHandler = handler | ||
? handler(initialProps, initialContext) | ||
: function () { return void 0; }; | ||
return function (effect) { | ||
@@ -251,4 +255,4 @@ if (isValidElement$$1(effect)) { | ||
_a); | ||
var component = createComponent(instance, dataObservable, pushEvent); | ||
var sinkObservable = aperture(instance.props, instance.context)(component); | ||
var component = createComponent(function (propName) { return instance.props[propName]; }, dataObservable, pushEvent); | ||
var sinkObservable = aperture(component, instance.props, instance.context); | ||
var sinkSubscription = subscribeToSink(sinkObservable, finalHandler(instance.props, instance.context), errorHandler | ||
@@ -305,3 +309,3 @@ ? errorHandler(instance.props, instance.context) | ||
var _a; | ||
}; }; | ||
}; | ||
@@ -314,40 +318,43 @@ var isComponentClass = function (ComponentClass) { | ||
var Empty = function () { return null; }; | ||
var withEffects = function (handler, errorHandler, Context) { return function (aperture) { return function (BaseComponent) { | ||
if (BaseComponent === void 0) { BaseComponent = Empty; } | ||
return _a = /** @class */ (function (_super) { | ||
__extends(WithEffects, _super); | ||
function WithEffects(props, context) { | ||
var _this = _super.call(this, props, context) || this; | ||
_this.mounted = false; | ||
_this.unmounted = false; | ||
configureComponent(handler, errorHandler)(aperture, _this, isValidElement, isComponentClass); | ||
return _this; | ||
} | ||
WithEffects.prototype.componentDidMount = function () { | ||
this.mounted = true; | ||
this.triggerMount(); | ||
}; | ||
WithEffects.prototype.componentWillReceiveProps = function (nextProps) { | ||
this.reDecorateProps(nextProps); | ||
this.pushProps(nextProps); | ||
}; | ||
WithEffects.prototype.shouldComponentUpdate = function (nextProps, nextState) { | ||
return this.havePropsChanged(nextProps, nextState); | ||
}; | ||
WithEffects.prototype.componentWillUnmount = function () { | ||
this.unmounted = true; | ||
this.triggerUnmount(); | ||
}; | ||
WithEffects.prototype.render = function () { | ||
if (this.state.children) { | ||
return this.state.children; | ||
var withEffects = function (aperture, config) { | ||
if (config === void 0) { config = {}; } | ||
return function (BaseComponent) { | ||
if (BaseComponent === void 0) { BaseComponent = Empty; } | ||
return _a = /** @class */ (function (_super) { | ||
__extends(WithEffects, _super); | ||
function WithEffects(props, context) { | ||
var _this = _super.call(this, props, context) || this; | ||
_this.mounted = false; | ||
_this.unmounted = false; | ||
configureComponent(aperture, _this, isValidElement, isComponentClass, config.handler, config.errorHandler); | ||
return _this; | ||
} | ||
return createElement(BaseComponent, this.getChildProps()); | ||
}; | ||
return WithEffects; | ||
}(Component)), | ||
_a.contextType = Context, | ||
_a; | ||
var _a; | ||
}; }; }; | ||
WithEffects.prototype.componentDidMount = function () { | ||
this.mounted = true; | ||
this.triggerMount(); | ||
}; | ||
WithEffects.prototype.componentWillReceiveProps = function (nextProps) { | ||
this.reDecorateProps(nextProps); | ||
this.pushProps(nextProps); | ||
}; | ||
WithEffects.prototype.shouldComponentUpdate = function (nextProps, nextState) { | ||
return this.havePropsChanged(nextProps, nextState); | ||
}; | ||
WithEffects.prototype.componentWillUnmount = function () { | ||
this.unmounted = true; | ||
this.triggerUnmount(); | ||
}; | ||
WithEffects.prototype.render = function () { | ||
if (this.state.children) { | ||
return this.state.children; | ||
} | ||
return createElement(BaseComponent, this.getChildProps()); | ||
}; | ||
return WithEffects; | ||
}(Component)), | ||
_a.contextType = config.Context, | ||
_a; | ||
var _a; | ||
}; | ||
}; | ||
@@ -371,2 +378,90 @@ var identity = function (arg) { return arg; }; | ||
export { withEffects, compose, asProps, toProps, PROPS_EFFECT }; | ||
var configureHook = function (aperture, data, handler, errorHandler) { | ||
if (handler === void 0) { handler = function () { return function () { return void 0; }; }; } | ||
var returnedData; | ||
var lastData = data; | ||
var setComponentData; | ||
var finalHandler = function (initialData) { | ||
var effectHandler = handler(initialData); | ||
return function (effect) { | ||
if (effect && effect.type === COMPONENT_EFFECT) { | ||
if (setComponentData) { | ||
setComponentData(effect.payload); | ||
} | ||
else { | ||
returnedData = effect.payload; | ||
} | ||
} | ||
else { | ||
effectHandler(effect); | ||
} | ||
}; | ||
}; | ||
var listeners = []; | ||
var addListener = function (listener) { | ||
listeners = listeners.concat(listener); | ||
}; | ||
var removeListener = function (listener) { | ||
listeners = listeners.filter(function (l) { return l !== listener; }); | ||
}; | ||
var pushEvent = function (eventName) { return function (val) { | ||
listeners.forEach(function (listener) { | ||
listener.next(createEventData(eventName, val)); | ||
}); | ||
}; }; | ||
var dataObservable = (_a = { | ||
subscribe: function (listener) { | ||
addListener(listener); | ||
listener.next(createPropsData(lastData)); | ||
return { unsubscribe: function () { return removeListener(listener); } }; | ||
} | ||
}, | ||
_a[$$observable] = function () { | ||
return this; | ||
}, | ||
_a); | ||
var component = createComponent(function (propName) { return data[propName]; }, dataObservable, pushEvent); | ||
var sinkObservable = aperture(component, data); | ||
var sinkSubscription = subscribeToSink(sinkObservable, finalHandler(data), errorHandler ? errorHandler(data) : undefined); | ||
var pushMountEvent = function () { | ||
pushEvent(MOUNT_EVENT)(undefined); | ||
}; | ||
var pushUnmountEvent = function () { | ||
pushEvent(UNMOUNT_EVENT)(undefined); | ||
}; | ||
return { | ||
data: returnedData, | ||
unsubscribe: function () { | ||
pushUnmountEvent(); | ||
sinkSubscription.unsubscribe(); | ||
}, | ||
pushMountEvent: pushMountEvent, | ||
pushData: function (data) { | ||
lastData = data; | ||
listeners.forEach(function (listener) { | ||
listener.next(createPropsData(data)); | ||
}); | ||
}, | ||
registerSetData: function (setData) { | ||
setComponentData = function (data) { return setData(function (hook) { return (__assign({}, hook, { data: data })); }); }; | ||
} | ||
}; | ||
var _a; | ||
}; | ||
// @ts-ignore | ||
var useRefract = function (aperture, data, config) { | ||
if (config === void 0) { config = {}; } | ||
var _a = useState(configureHook(aperture, data, config.handler, config.errorHandler)), hook = _a[0], setData = _a[1]; | ||
useLayoutEffect(function () { | ||
hook.registerSetData(setData); | ||
hook.pushMountEvent(); | ||
return function () { return hook.unsubscribe(); }; | ||
}, []); | ||
useEffect(function () { | ||
hook.pushData(data); | ||
}); | ||
return hook.data; | ||
}; | ||
export { withEffects, compose, asProps, toProps, PROPS_EFFECT, useRefract, toRender, COMPONENT_EFFECT }; |
254
index.js
@@ -47,2 +47,3 @@ 'use strict'; | ||
var PROPS_EFFECT = '@@refract/effect/props'; | ||
var COMPONENT_EFFECT = '@@refract/effect/component'; | ||
var toProps = function (props) { return ({ | ||
@@ -62,2 +63,6 @@ type: PROPS_EFFECT, | ||
}); }; | ||
var toRender = function (data) { return ({ | ||
type: COMPONENT_EFFECT, | ||
payload: data | ||
}); }; | ||
@@ -112,8 +117,5 @@ var MOUNT_EVENT = '@@refract/event/mount'; | ||
}; | ||
var createComponent = function (instance, dataObservable, pushEvent) { | ||
var data = function () { return xs.from(dataObservable); }; | ||
var getComponentBase = function (data, pushEvent) { | ||
var fromEvent = function (eventName, valueTransformer) { | ||
return data() | ||
.filter(isEvent(eventName)) | ||
.map(function (data) { | ||
return data.filter(isEvent(eventName)).map(function (data) { | ||
var value = data.payload.value; | ||
@@ -124,33 +126,4 @@ return valueTransformer ? valueTransformer(value) : value; | ||
return { | ||
mount: data() | ||
.filter(isEvent(MOUNT_EVENT)) | ||
.mapTo(undefined), | ||
unmount: data() | ||
.filter(isEvent(UNMOUNT_EVENT)) | ||
.mapTo(undefined), | ||
observe: function (propName, valueTransformer) { | ||
if (propName && typeof instance.props[propName] === 'function') { | ||
return data() | ||
.filter(isCallback(propName)) | ||
.map(function (data) { | ||
var args = data.payload.args; | ||
return valueTransformer | ||
? valueTransformer(args) | ||
: args[0]; | ||
}); | ||
} | ||
if (propName) { | ||
return data() | ||
.filter(isProps) | ||
.map(function (data) { | ||
var prop = data.payload[propName]; | ||
return valueTransformer ? valueTransformer(prop) : prop; | ||
}) | ||
.compose(dropRepeats()); | ||
} | ||
return data() | ||
.filter(isProps) | ||
.map(function (data) { return data.payload; }) | ||
.compose(dropRepeats(shallowEquals)); | ||
}, | ||
mount: data.filter(isEvent(MOUNT_EVENT)).mapTo(undefined), | ||
unmount: data.filter(isEvent(UNMOUNT_EVENT)).mapTo(undefined), | ||
fromEvent: fromEvent, | ||
@@ -170,4 +143,33 @@ pushEvent: pushEvent, | ||
}; | ||
var getObserve = function (getProp, data) { | ||
return function observe(propName, valueTransformer) { | ||
if (propName && typeof getProp(propName) === 'function') { | ||
return data() | ||
.filter(isCallback(propName)) | ||
.map(function (data) { | ||
var args = data.payload.args; | ||
return valueTransformer ? valueTransformer(args) : args[0]; | ||
}); | ||
} | ||
if (propName) { | ||
return data() | ||
.filter(isProps) | ||
.map(function (data) { | ||
var prop = data.payload[propName]; | ||
return valueTransformer ? valueTransformer(prop) : prop; | ||
}) | ||
.compose(dropRepeats()); | ||
} | ||
return data() | ||
.filter(isProps) | ||
.map(function (data) { return data.payload; }) | ||
.compose(dropRepeats(shallowEquals)); | ||
}; | ||
}; | ||
var createComponent = function (getProp, dataObservable, pushEvent) { | ||
var data = function () { return xs.from(dataObservable); }; | ||
return __assign({ observe: getObserve(getProp, data) }, getComponentBase(data(), pushEvent)); | ||
}; | ||
var configureComponent = function (handler, errorHandler) { return function (aperture, instance, isValidElement, isComponentClass) { | ||
var configureComponent = function (aperture, instance, isValidElement, isComponentClass, handler, errorHandler) { | ||
if (isValidElement === void 0) { isValidElement = function () { return false; }; } | ||
@@ -192,3 +194,5 @@ if (isComponentClass === void 0) { isComponentClass = function () { return false; }; } | ||
var finalHandler = function (initialProps, initialContext) { | ||
var effectHandler = handler(initialProps, initialContext); | ||
var effectHandler = handler | ||
? handler(initialProps, initialContext) | ||
: function () { return void 0; }; | ||
return function (effect) { | ||
@@ -257,4 +261,4 @@ if (isValidElement(effect)) { | ||
_a); | ||
var component = createComponent(instance, dataObservable, pushEvent); | ||
var sinkObservable = aperture(instance.props, instance.context)(component); | ||
var component = createComponent(function (propName) { return instance.props[propName]; }, dataObservable, pushEvent); | ||
var sinkObservable = aperture(component, instance.props, instance.context); | ||
var sinkSubscription = subscribeToSink(sinkObservable, finalHandler(instance.props, instance.context), errorHandler | ||
@@ -311,3 +315,3 @@ ? errorHandler(instance.props, instance.context) | ||
var _a; | ||
}; }; | ||
}; | ||
@@ -320,40 +324,43 @@ var isComponentClass = function (ComponentClass) { | ||
var Empty = function () { return null; }; | ||
var withEffects = function (handler, errorHandler, Context) { return function (aperture) { return function (BaseComponent) { | ||
if (BaseComponent === void 0) { BaseComponent = Empty; } | ||
return _a = /** @class */ (function (_super) { | ||
__extends(WithEffects, _super); | ||
function WithEffects(props, context) { | ||
var _this = _super.call(this, props, context) || this; | ||
_this.mounted = false; | ||
_this.unmounted = false; | ||
configureComponent(handler, errorHandler)(aperture, _this, React.isValidElement, isComponentClass); | ||
return _this; | ||
} | ||
WithEffects.prototype.componentDidMount = function () { | ||
this.mounted = true; | ||
this.triggerMount(); | ||
}; | ||
WithEffects.prototype.componentWillReceiveProps = function (nextProps) { | ||
this.reDecorateProps(nextProps); | ||
this.pushProps(nextProps); | ||
}; | ||
WithEffects.prototype.shouldComponentUpdate = function (nextProps, nextState) { | ||
return this.havePropsChanged(nextProps, nextState); | ||
}; | ||
WithEffects.prototype.componentWillUnmount = function () { | ||
this.unmounted = true; | ||
this.triggerUnmount(); | ||
}; | ||
WithEffects.prototype.render = function () { | ||
if (this.state.children) { | ||
return this.state.children; | ||
var withEffects = function (aperture, config) { | ||
if (config === void 0) { config = {}; } | ||
return function (BaseComponent) { | ||
if (BaseComponent === void 0) { BaseComponent = Empty; } | ||
return _a = /** @class */ (function (_super) { | ||
__extends(WithEffects, _super); | ||
function WithEffects(props, context) { | ||
var _this = _super.call(this, props, context) || this; | ||
_this.mounted = false; | ||
_this.unmounted = false; | ||
configureComponent(aperture, _this, React.isValidElement, isComponentClass, config.handler, config.errorHandler); | ||
return _this; | ||
} | ||
return React.createElement(BaseComponent, this.getChildProps()); | ||
}; | ||
return WithEffects; | ||
}(React.Component)), | ||
_a.contextType = Context, | ||
_a; | ||
var _a; | ||
}; }; }; | ||
WithEffects.prototype.componentDidMount = function () { | ||
this.mounted = true; | ||
this.triggerMount(); | ||
}; | ||
WithEffects.prototype.componentWillReceiveProps = function (nextProps) { | ||
this.reDecorateProps(nextProps); | ||
this.pushProps(nextProps); | ||
}; | ||
WithEffects.prototype.shouldComponentUpdate = function (nextProps, nextState) { | ||
return this.havePropsChanged(nextProps, nextState); | ||
}; | ||
WithEffects.prototype.componentWillUnmount = function () { | ||
this.unmounted = true; | ||
this.triggerUnmount(); | ||
}; | ||
WithEffects.prototype.render = function () { | ||
if (this.state.children) { | ||
return this.state.children; | ||
} | ||
return React.createElement(BaseComponent, this.getChildProps()); | ||
}; | ||
return WithEffects; | ||
}(React.Component)), | ||
_a.contextType = config.Context, | ||
_a; | ||
var _a; | ||
}; | ||
}; | ||
@@ -377,2 +384,90 @@ var identity = function (arg) { return arg; }; | ||
var configureHook = function (aperture, data, handler, errorHandler) { | ||
if (handler === void 0) { handler = function () { return function () { return void 0; }; }; } | ||
var returnedData; | ||
var lastData = data; | ||
var setComponentData; | ||
var finalHandler = function (initialData) { | ||
var effectHandler = handler(initialData); | ||
return function (effect) { | ||
if (effect && effect.type === COMPONENT_EFFECT) { | ||
if (setComponentData) { | ||
setComponentData(effect.payload); | ||
} | ||
else { | ||
returnedData = effect.payload; | ||
} | ||
} | ||
else { | ||
effectHandler(effect); | ||
} | ||
}; | ||
}; | ||
var listeners = []; | ||
var addListener = function (listener) { | ||
listeners = listeners.concat(listener); | ||
}; | ||
var removeListener = function (listener) { | ||
listeners = listeners.filter(function (l) { return l !== listener; }); | ||
}; | ||
var pushEvent = function (eventName) { return function (val) { | ||
listeners.forEach(function (listener) { | ||
listener.next(createEventData(eventName, val)); | ||
}); | ||
}; }; | ||
var dataObservable = (_a = { | ||
subscribe: function (listener) { | ||
addListener(listener); | ||
listener.next(createPropsData(lastData)); | ||
return { unsubscribe: function () { return removeListener(listener); } }; | ||
} | ||
}, | ||
_a[$$observable] = function () { | ||
return this; | ||
}, | ||
_a); | ||
var component = createComponent(function (propName) { return data[propName]; }, dataObservable, pushEvent); | ||
var sinkObservable = aperture(component, data); | ||
var sinkSubscription = subscribeToSink(sinkObservable, finalHandler(data), errorHandler ? errorHandler(data) : undefined); | ||
var pushMountEvent = function () { | ||
pushEvent(MOUNT_EVENT)(undefined); | ||
}; | ||
var pushUnmountEvent = function () { | ||
pushEvent(UNMOUNT_EVENT)(undefined); | ||
}; | ||
return { | ||
data: returnedData, | ||
unsubscribe: function () { | ||
pushUnmountEvent(); | ||
sinkSubscription.unsubscribe(); | ||
}, | ||
pushMountEvent: pushMountEvent, | ||
pushData: function (data) { | ||
lastData = data; | ||
listeners.forEach(function (listener) { | ||
listener.next(createPropsData(data)); | ||
}); | ||
}, | ||
registerSetData: function (setData) { | ||
setComponentData = function (data) { return setData(function (hook) { return (__assign({}, hook, { data: data })); }); }; | ||
} | ||
}; | ||
var _a; | ||
}; | ||
// @ts-ignore | ||
var useRefract = function (aperture, data, config) { | ||
if (config === void 0) { config = {}; } | ||
var _a = React.useState(configureHook(aperture, data, config.handler, config.errorHandler)), hook = _a[0], setData = _a[1]; | ||
React.useLayoutEffect(function () { | ||
hook.registerSetData(setData); | ||
hook.pushMountEvent(); | ||
return function () { return hook.unsubscribe(); }; | ||
}, []); | ||
React.useEffect(function () { | ||
hook.pushData(data); | ||
}); | ||
return hook.data; | ||
}; | ||
exports.withEffects = withEffects; | ||
@@ -383,1 +478,4 @@ exports.compose = compose; | ||
exports.PROPS_EFFECT = PROPS_EFFECT; | ||
exports.useRefract = useRefract; | ||
exports.toRender = toRender; | ||
exports.COMPONENT_EFFECT = COMPONENT_EFFECT; |
{ | ||
"name": "refract-xstream", | ||
"description": "Refract bindings for React with xstream: harness the power of reactive programming to supercharge your components!", | ||
"version": "2.2.0", | ||
"version": "3.0.0", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "jsnext:main": "index.es.js", |
@@ -82,3 +82,3 @@ <p align="center"> | ||
```js | ||
const aperture = initialProps => component => { | ||
const aperture = component => { | ||
return component.observe('username').pipe( | ||
@@ -102,3 +102,3 @@ debounce(2000), | ||
const WrappedComponent = withEffects(handler)(aperture)(BaseComponent) | ||
const WrappedComponent = withEffects(aperture, { handler })(BaseComponent) | ||
``` | ||
@@ -110,3 +110,3 @@ | ||
Signature: `(initialProps) => (component) => { return effectStream }`. | ||
Signature: `(component, initialProps) => { return effectStream }`. | ||
@@ -131,8 +131,10 @@ * The `initialProps` are all props passed into the `WrappedComponent`. | ||
Signature: `(handler) => (aperture) => (Component) => { return WrappedComponent }` | ||
Signature: `(aperture, { handler }) => (Component) => { return WrappedComponent }` | ||
* The hoc takes in three curried arguments: | ||
* A `handler` function | ||
* The hoc takes in two arguments, followed by a component: | ||
* An `aperture` function | ||
* A React `Component` | ||
* An optional `config` object accepting | ||
* a `handler` function | ||
* a `errorHandler` function | ||
* a `Context` object (React only) | ||
* The hoc returns a `WrappedComponent` - an enhanced version of your original `Component` which includes your side-effect logic. | ||
@@ -139,0 +141,0 @@ |
export declare type Handler<P, E, C = any> = ( | ||
intialProps: P, | ||
initialContext: C | ||
initialContext?: C | ||
) => (val: E) => void | ||
export declare type ErrorHandler<P, C = any> = ( | ||
intialProps: P, | ||
initialContext: C | ||
initialContext?: C | ||
) => (error: any) => void | ||
export declare type PushEvent = (eventName: string) => <T>(val: T) => void |
import { Handler, ErrorHandler } from './baseTypes' | ||
import { Aperture } from './observable' | ||
declare const configureComponent: <P, E, Ctx>( | ||
handler: Handler<P, E, Ctx>, | ||
errorHandler?: ErrorHandler<P, any> | ||
) => ( | ||
aperture: Aperture<P, E, Ctx>, | ||
instance: any, | ||
isValidElement?: (val: any) => boolean, | ||
isComponentClass?: (val: any) => boolean | ||
isComponentClass?: (val: any) => boolean, | ||
handler?: Handler<P, E, Ctx>, | ||
errorHandler?: ErrorHandler<P, any> | ||
) => void | ||
export default configureComponent |
export declare const PROPS_EFFECT: string | ||
export declare const COMPONENT_EFFECT: string | ||
export interface PropEffect<P = object> { | ||
@@ -9,3 +10,8 @@ type: string | ||
} | ||
export interface ComponentEffect<D = object> { | ||
type: string | ||
payload: D | ||
} | ||
export declare const toProps: <P>(props: P) => PropEffect<P> | ||
export declare const asProps: <P>(props: P) => PropEffect<P> | ||
export declare const toRender: <D>(data: D) => ComponentEffect<D> |
import { withEffects } from './withEffects' | ||
import { ObservableComponent, Aperture } from './observable' | ||
import { | ||
ObservableComponent, | ||
Aperture, | ||
ObservableComponentBase | ||
} from './observable' | ||
import { ErrorHandler, Handler, PushEvent } from './baseTypes' | ||
import { compose, Compose } from './compose' | ||
import { asProps, toProps, PROPS_EFFECT, PropEffect } from './effects' | ||
import { | ||
asProps, | ||
toProps, | ||
PROPS_EFFECT, | ||
PropEffect, | ||
toRender, | ||
COMPONENT_EFFECT, | ||
ComponentEffect | ||
} from './effects' | ||
import { useRefract } from './refractHook' | ||
export { | ||
@@ -18,3 +31,8 @@ withEffects, | ||
PropEffect, | ||
PROPS_EFFECT | ||
PROPS_EFFECT, | ||
useRefract, | ||
ObservableComponentBase, | ||
toRender, | ||
COMPONENT_EFFECT, | ||
ComponentEffect | ||
} |
import { Stream, Listener, Subscription } from 'xstream' | ||
import { PushEvent } from './baseTypes' | ||
export { Listener, Subscription } | ||
export interface ObservableComponent { | ||
observe: <T>( | ||
propName?: string, | ||
valueTransformer?: (val: any) => T | ||
) => Stream<T> | ||
export interface ObservableComponentBase { | ||
mount: Stream<any> | ||
unmount: Stream<any> | ||
fromEvent: <T>( | ||
@@ -13,4 +11,2 @@ eventName: string, | ||
) => Stream<T> | ||
mount: Stream<any> | ||
unmount: Stream<any> | ||
pushEvent: PushEvent | ||
@@ -22,6 +18,14 @@ useEvent: <T>( | ||
} | ||
export interface Observe { | ||
observe: <T>( | ||
propName?: string, | ||
valueTransformer?: (val: any) => T | ||
) => Stream<T> | ||
} | ||
export declare type ObservableComponent = Observe & ObservableComponentBase | ||
export declare type Aperture<P, E, C = any> = ( | ||
component: ObservableComponent, | ||
initialProps: P, | ||
initialContext: C | ||
) => (component: ObservableComponent) => Stream<E> | ||
initialContext?: C | ||
) => Stream<E> | ||
export declare const subscribeToSink: <T>( | ||
@@ -32,6 +36,10 @@ sink: Stream<T>, | ||
) => Subscription | ||
export declare const getObserve: <P>( | ||
getProp: any, | ||
data: any | ||
) => <T>(propName?: any, valueTransformer?: any) => any | ||
export declare const createComponent: <P>( | ||
instance: any, | ||
getProp: any, | ||
dataObservable: any, | ||
pushEvent: PushEvent | ||
) => ObservableComponent |
@@ -11,9 +11,11 @@ /// <reference types="react" /> | ||
} | ||
export interface Config<P, E, C = any> { | ||
handler?: Handler<P, E, C> | ||
errorHandler?: ErrorHandler<P, C> | ||
Context?: React.Context<C> | ||
} | ||
export declare const withEffects: <P, E, CP = P, C = any>( | ||
handler: Handler<P, E, C>, | ||
errorHandler?: ErrorHandler<P, C>, | ||
Context?: React.Context<C> | ||
aperture: Aperture<P, E, C>, | ||
config?: Config<P, E, C> | ||
) => ( | ||
aperture: Aperture<P, E, C> | ||
) => ( | ||
BaseComponent?: React.ComponentType< | ||
@@ -24,2 +26,2 @@ CP & { | ||
> | ||
) => React.ComponentClass<P> | ||
) => React.ComponentClass<P, any> |
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
51658
14
1148
169