refract-xstream
Advanced tools
Comparing version 3.1.0 to 4.0.0
@@ -116,2 +116,17 @@ import xs from 'xstream'; | ||
}; | ||
var useEvent = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var eventName = args[0]; | ||
var hasSeedValue = args.length > 1; | ||
var seedValue = args[2]; | ||
var events$ = fromEvent(eventName); | ||
var pushEventValue = pushEvent(eventName); | ||
return [ | ||
hasSeedValue ? events$ : events$.startWith(seedValue), | ||
pushEventValue | ||
]; | ||
}; | ||
return { | ||
@@ -122,17 +137,10 @@ mount: data.filter(isEvent(MOUNT_EVENT)).mapTo(undefined), | ||
pushEvent: pushEvent, | ||
useEvent: function (eventName, seedValue) { | ||
var events$ = fromEvent(eventName); | ||
var pushEventValue = pushEvent(eventName); | ||
return [ | ||
seedValue === undefined | ||
? events$ | ||
: events$.startWith(seedValue), | ||
pushEventValue | ||
]; | ||
} | ||
useEvent: useEvent | ||
}; | ||
}; | ||
var getObserve = function (getProp, data) { | ||
var getObserve = function (getProp, data, decoratedProps) { | ||
return function observe(propName, valueTransformer) { | ||
if (propName && typeof getProp(propName) === 'function') { | ||
if (decoratedProps && | ||
propName && | ||
typeof getProp(propName) === 'function') { | ||
return data() | ||
@@ -160,8 +168,8 @@ .filter(isCallback(propName)) | ||
}; | ||
var createComponent = function (getProp, dataObservable, pushEvent) { | ||
var createComponent = function (getProp, dataObservable, pushEvent, decoratedProps) { | ||
var data = function () { return xs.from(dataObservable); }; | ||
return __assign({ observe: getObserve(getProp, data) }, getComponentBase(data(), pushEvent)); | ||
return __assign({ observe: getObserve(getProp, data, decoratedProps) }, getComponentBase(data(), pushEvent)); | ||
}; | ||
var configureComponent = function (aperture, instance, isValidElement$$1, isComponentClass, handler, errorHandler, mergeProps) { | ||
var configureComponent = function (aperture, instance, isValidElement$$1, isComponentClass, handler, errorHandler, mergeProps, decorateProps) { | ||
if (isValidElement$$1 === void 0) { isValidElement$$1 = function () { return false; }; } | ||
@@ -237,7 +245,9 @@ if (isComponentClass === void 0) { isComponentClass = function () { return false; }; } | ||
}; | ||
Object.keys(instance.props).forEach(function (propName) { | ||
if (typeof instance.props[propName] === 'function') { | ||
decorateProp(decoratedProps, instance.props[propName], propName); | ||
} | ||
}); | ||
if (decorateProps) { | ||
Object.keys(instance.props).forEach(function (propName) { | ||
if (typeof instance.props[propName] === 'function') { | ||
decorateProp(decoratedProps, instance.props[propName], propName); | ||
} | ||
}); | ||
} | ||
var dataObservable = (_a = { | ||
@@ -254,3 +264,3 @@ subscribe: function (listener) { | ||
_a); | ||
var component = createComponent(function (propName) { return instance.props[propName]; }, dataObservable, pushEvent); | ||
var component = createComponent(function (propName) { return instance.props[propName]; }, dataObservable, pushEvent, decorateProps); | ||
var sinkObservable = aperture(component, instance.props, instance.context); | ||
@@ -261,8 +271,10 @@ var sinkSubscription = subscribeToSink(sinkObservable, finalHandler(instance.props, instance.context), errorHandler | ||
instance.reDecorateProps = function (nextProps) { | ||
Object.keys(nextProps).forEach(function (propName) { | ||
if (typeof instance.props[propName] === 'function' && | ||
nextProps[propName] !== instance.props[propName]) { | ||
decorateProp(decoratedProps, nextProps[propName], propName); | ||
} | ||
}); | ||
if (decorateProps) { | ||
Object.keys(nextProps).forEach(function (propName) { | ||
if (typeof instance.props[propName] === 'function' && | ||
nextProps[propName] !== instance.props[propName]) { | ||
decorateProp(decoratedProps, nextProps[propName], propName); | ||
} | ||
}); | ||
} | ||
}; | ||
@@ -275,6 +287,6 @@ instance.pushProps = function (props) { | ||
instance.triggerMount = function () { | ||
pushEvent(MOUNT_EVENT)(undefined); | ||
pushEvent(MOUNT_EVENT)(); | ||
}; | ||
instance.triggerUnmount = function () { | ||
pushEvent(UNMOUNT_EVENT)(undefined); | ||
pushEvent(UNMOUNT_EVENT)(); | ||
sinkSubscription.unsubscribe(); | ||
@@ -290,3 +302,3 @@ }; | ||
if (state.replace === false) { | ||
return __assign({}, instance.props, stateProps, additionalProps); | ||
return __assign({}, instance.props, additionalProps, stateProps); | ||
} | ||
@@ -329,3 +341,3 @@ return __assign({}, instance.props, additionalProps); | ||
_this.unmounted = false; | ||
configureComponent(aperture, _this, isValidElement, isComponentClass, config.handler, config.errorHandler, config.mergeProps); | ||
configureComponent(aperture, _this, isValidElement, isComponentClass, config.handler, config.errorHandler, config.mergeProps, config.decorateProps !== false); | ||
return _this; | ||
@@ -423,10 +435,10 @@ } | ||
_a); | ||
var component = createComponent(function (propName) { return data[propName]; }, dataObservable, pushEvent); | ||
var component = createComponent(function (propName) { return data[propName]; }, dataObservable, pushEvent, false); | ||
var sinkObservable = aperture(component, data); | ||
var sinkSubscription = subscribeToSink(sinkObservable, finalHandler(data), errorHandler ? errorHandler(data) : undefined); | ||
var pushMountEvent = function () { | ||
pushEvent(MOUNT_EVENT)(undefined); | ||
pushEvent(MOUNT_EVENT)(); | ||
}; | ||
var pushUnmountEvent = function () { | ||
pushEvent(UNMOUNT_EVENT)(undefined); | ||
pushEvent(UNMOUNT_EVENT)(); | ||
}; | ||
@@ -433,0 +445,0 @@ return { |
80
index.js
@@ -122,2 +122,17 @@ 'use strict'; | ||
}; | ||
var useEvent = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var eventName = args[0]; | ||
var hasSeedValue = args.length > 1; | ||
var seedValue = args[2]; | ||
var events$ = fromEvent(eventName); | ||
var pushEventValue = pushEvent(eventName); | ||
return [ | ||
hasSeedValue ? events$ : events$.startWith(seedValue), | ||
pushEventValue | ||
]; | ||
}; | ||
return { | ||
@@ -128,17 +143,10 @@ mount: data.filter(isEvent(MOUNT_EVENT)).mapTo(undefined), | ||
pushEvent: pushEvent, | ||
useEvent: function (eventName, seedValue) { | ||
var events$ = fromEvent(eventName); | ||
var pushEventValue = pushEvent(eventName); | ||
return [ | ||
seedValue === undefined | ||
? events$ | ||
: events$.startWith(seedValue), | ||
pushEventValue | ||
]; | ||
} | ||
useEvent: useEvent | ||
}; | ||
}; | ||
var getObserve = function (getProp, data) { | ||
var getObserve = function (getProp, data, decoratedProps) { | ||
return function observe(propName, valueTransformer) { | ||
if (propName && typeof getProp(propName) === 'function') { | ||
if (decoratedProps && | ||
propName && | ||
typeof getProp(propName) === 'function') { | ||
return data() | ||
@@ -166,8 +174,8 @@ .filter(isCallback(propName)) | ||
}; | ||
var createComponent = function (getProp, dataObservable, pushEvent) { | ||
var createComponent = function (getProp, dataObservable, pushEvent, decoratedProps) { | ||
var data = function () { return xs.from(dataObservable); }; | ||
return __assign({ observe: getObserve(getProp, data) }, getComponentBase(data(), pushEvent)); | ||
return __assign({ observe: getObserve(getProp, data, decoratedProps) }, getComponentBase(data(), pushEvent)); | ||
}; | ||
var configureComponent = function (aperture, instance, isValidElement, isComponentClass, handler, errorHandler, mergeProps) { | ||
var configureComponent = function (aperture, instance, isValidElement, isComponentClass, handler, errorHandler, mergeProps, decorateProps) { | ||
if (isValidElement === void 0) { isValidElement = function () { return false; }; } | ||
@@ -243,7 +251,9 @@ if (isComponentClass === void 0) { isComponentClass = function () { return false; }; } | ||
}; | ||
Object.keys(instance.props).forEach(function (propName) { | ||
if (typeof instance.props[propName] === 'function') { | ||
decorateProp(decoratedProps, instance.props[propName], propName); | ||
} | ||
}); | ||
if (decorateProps) { | ||
Object.keys(instance.props).forEach(function (propName) { | ||
if (typeof instance.props[propName] === 'function') { | ||
decorateProp(decoratedProps, instance.props[propName], propName); | ||
} | ||
}); | ||
} | ||
var dataObservable = (_a = { | ||
@@ -260,3 +270,3 @@ subscribe: function (listener) { | ||
_a); | ||
var component = createComponent(function (propName) { return instance.props[propName]; }, dataObservable, pushEvent); | ||
var component = createComponent(function (propName) { return instance.props[propName]; }, dataObservable, pushEvent, decorateProps); | ||
var sinkObservable = aperture(component, instance.props, instance.context); | ||
@@ -267,8 +277,10 @@ var sinkSubscription = subscribeToSink(sinkObservable, finalHandler(instance.props, instance.context), errorHandler | ||
instance.reDecorateProps = function (nextProps) { | ||
Object.keys(nextProps).forEach(function (propName) { | ||
if (typeof instance.props[propName] === 'function' && | ||
nextProps[propName] !== instance.props[propName]) { | ||
decorateProp(decoratedProps, nextProps[propName], propName); | ||
} | ||
}); | ||
if (decorateProps) { | ||
Object.keys(nextProps).forEach(function (propName) { | ||
if (typeof instance.props[propName] === 'function' && | ||
nextProps[propName] !== instance.props[propName]) { | ||
decorateProp(decoratedProps, nextProps[propName], propName); | ||
} | ||
}); | ||
} | ||
}; | ||
@@ -281,6 +293,6 @@ instance.pushProps = function (props) { | ||
instance.triggerMount = function () { | ||
pushEvent(MOUNT_EVENT)(undefined); | ||
pushEvent(MOUNT_EVENT)(); | ||
}; | ||
instance.triggerUnmount = function () { | ||
pushEvent(UNMOUNT_EVENT)(undefined); | ||
pushEvent(UNMOUNT_EVENT)(); | ||
sinkSubscription.unsubscribe(); | ||
@@ -296,3 +308,3 @@ }; | ||
if (state.replace === false) { | ||
return __assign({}, instance.props, stateProps, additionalProps); | ||
return __assign({}, instance.props, additionalProps, stateProps); | ||
} | ||
@@ -335,3 +347,3 @@ return __assign({}, instance.props, additionalProps); | ||
_this.unmounted = false; | ||
configureComponent(aperture, _this, React.isValidElement, isComponentClass, config.handler, config.errorHandler, config.mergeProps); | ||
configureComponent(aperture, _this, React.isValidElement, isComponentClass, config.handler, config.errorHandler, config.mergeProps, config.decorateProps !== false); | ||
return _this; | ||
@@ -429,10 +441,10 @@ } | ||
_a); | ||
var component = createComponent(function (propName) { return data[propName]; }, dataObservable, pushEvent); | ||
var component = createComponent(function (propName) { return data[propName]; }, dataObservable, pushEvent, false); | ||
var sinkObservable = aperture(component, data); | ||
var sinkSubscription = subscribeToSink(sinkObservable, finalHandler(data), errorHandler ? errorHandler(data) : undefined); | ||
var pushMountEvent = function () { | ||
pushEvent(MOUNT_EVENT)(undefined); | ||
pushEvent(MOUNT_EVENT)(); | ||
}; | ||
var pushUnmountEvent = function () { | ||
pushEvent(UNMOUNT_EVENT)(undefined); | ||
pushEvent(UNMOUNT_EVENT)(); | ||
}; | ||
@@ -439,0 +451,0 @@ return { |
{ | ||
"name": "refract-xstream", | ||
"description": "Refract bindings for React with xstream: harness the power of reactive programming to supercharge your components!", | ||
"version": "3.1.0", | ||
"version": "4.0.0", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "jsnext:main": "index.es.js", |
@@ -9,2 +9,5 @@ export declare type Handler<P, E, C = any> = ( | ||
) => (error: any) => void | ||
export declare type PushEvent = (eventName: string) => <T>(val: T) => void | ||
export interface PushEvent { | ||
(eventName: string): () => void | ||
<T = any>(eventName: string): (val: T) => void | ||
} |
@@ -10,4 +10,5 @@ import { Handler, ErrorHandler } from './baseTypes' | ||
errorHandler?: ErrorHandler<P, any>, | ||
mergeProps?: boolean | ||
mergeProps?: boolean, | ||
decorateProps?: boolean | ||
) => void | ||
export default configureComponent |
@@ -5,3 +5,5 @@ import { withEffects } from './withEffects' | ||
Aperture, | ||
ObservableComponentBase | ||
ObservableComponentBase, | ||
UseEvent, | ||
FromEvent | ||
} from './observable' | ||
@@ -27,2 +29,4 @@ import { ErrorHandler, Handler, PushEvent } from './baseTypes' | ||
PushEvent, | ||
FromEvent, | ||
UseEvent, | ||
compose, | ||
@@ -29,0 +33,0 @@ Compose, |
import { Stream, Listener, Subscription } from 'xstream' | ||
import { PushEvent } from './baseTypes' | ||
export { Listener, Subscription } | ||
export interface UseEvent { | ||
(eventName: string): [Stream<void>, () => any] | ||
<T = any>(eventName: string, seedValue?: T): [Stream<T>, (val: T) => any] | ||
} | ||
export interface FromEvent { | ||
(eventName: string): Stream<void> | ||
<T>(eventName: string, valueTransformer?: (val: any) => T): Stream<T> | ||
} | ||
export interface ObservableComponentBase { | ||
mount: Stream<any> | ||
unmount: Stream<any> | ||
fromEvent: <T>( | ||
eventName: string, | ||
valueTransformer?: (val: any) => T | ||
) => Stream<T> | ||
fromEvent: FromEvent | ||
pushEvent: PushEvent | ||
useEvent: <T>( | ||
eventName: string, | ||
seedValue?: T | ||
) => [Stream<T>, (val: T) => any] | ||
useEvent: UseEvent | ||
} | ||
@@ -36,3 +38,4 @@ export interface Observe { | ||
getProp: any, | ||
data: any | ||
data: any, | ||
decoratedProps: any | ||
) => <T>(propName?: any, valueTransformer?: any) => any | ||
@@ -42,3 +45,4 @@ export declare const createComponent: <P>( | ||
dataObservable: any, | ||
pushEvent: PushEvent | ||
pushEvent: PushEvent, | ||
decoratedProps: boolean | ||
) => ObservableComponent |
@@ -16,2 +16,3 @@ /// <reference types="react" /> | ||
mergeProps?: boolean | ||
decorateProps?: boolean | ||
} | ||
@@ -18,0 +19,0 @@ export declare const withEffects: <P, E, CP = P, C = 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
52338
1189