refract-callbag
Advanced tools
Comparing version 1.0.0-2 to 1.0.0-3
@@ -30,2 +30,10 @@ import $$observable from 'symbol-observable'; | ||
var __assign = Object.assign || function __assign(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; | ||
}; | ||
var fromObs = require('callbag-from-obs'); | ||
@@ -80,3 +88,4 @@ var toObs = require('callbag-to-obs'); | ||
}); | ||
var createPropObservable = function (propName) { | ||
var createPropObservable = function (propName, opts) { | ||
var options = __assign({ initialValue: true }, opts); | ||
var listenerType = typeof _this.props[propName] === 'function' | ||
@@ -87,2 +96,5 @@ ? 'fnProps' | ||
_this.listeners[listenerType][propName] = (_this.listeners[listenerType][propName] || []).concat(listener); | ||
if (listenerType === 'props' && options.initialValue) { | ||
listener.next(_this.props[propName]); | ||
} | ||
return function () { | ||
@@ -96,9 +108,6 @@ _this.listeners[listenerType][propName].filter(function (l) { return l !== listener; }); | ||
unmount: unmountObservable, | ||
observe: function (propName) { | ||
return createPropObservable(propName); | ||
} | ||
observe: function (propName, options) { return createPropObservable(propName, options); } | ||
}; | ||
var sinkObservable = effectFactory(_this.props)(_this.component); | ||
_this.sinkSubscription = subscribeToSink(sinkObservable, effectHandler(_this.props), errorHandler); | ||
_this.sendNext(); | ||
return _this; | ||
@@ -105,0 +114,0 @@ } |
19
index.js
@@ -36,2 +36,10 @@ 'use strict'; | ||
var __assign = Object.assign || function __assign(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; | ||
}; | ||
var fromObs = require('callbag-from-obs'); | ||
@@ -86,3 +94,4 @@ var toObs = require('callbag-to-obs'); | ||
}); | ||
var createPropObservable = function (propName) { | ||
var createPropObservable = function (propName, opts) { | ||
var options = __assign({ initialValue: true }, opts); | ||
var listenerType = typeof _this.props[propName] === 'function' | ||
@@ -93,2 +102,5 @@ ? 'fnProps' | ||
_this.listeners[listenerType][propName] = (_this.listeners[listenerType][propName] || []).concat(listener); | ||
if (listenerType === 'props' && options.initialValue) { | ||
listener.next(_this.props[propName]); | ||
} | ||
return function () { | ||
@@ -102,9 +114,6 @@ _this.listeners[listenerType][propName].filter(function (l) { return l !== listener; }); | ||
unmount: unmountObservable, | ||
observe: function (propName) { | ||
return createPropObservable(propName); | ||
} | ||
observe: function (propName, options) { return createPropObservable(propName, options); } | ||
}; | ||
var sinkObservable = effectFactory(_this.props)(_this.component); | ||
_this.sinkSubscription = subscribeToSink(sinkObservable, effectHandler(_this.props), errorHandler); | ||
_this.sendNext(); | ||
return _this; | ||
@@ -111,0 +120,0 @@ } |
{ | ||
"name": "refract-callbag", | ||
"version": "1.0.0-2", | ||
"version": "1.0.0-3", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "jsnext:main": "index.es.js", |
@@ -15,1 +15,5 @@ import { Listener } from './observable' | ||
export type EffectHandler<P, E> = (intialProps: P) => (val: E) => void | ||
export interface ObserveOptions { | ||
initialValue: boolean | ||
} |
import { withEffects } from './withEffects' | ||
import { ObservableComponent, EffectFactory } from './observable' | ||
import { EffectHandler } from './baseTypes' | ||
import { EffectHandler, ObserveOptions } from './baseTypes' | ||
export { withEffects, ObservableComponent, EffectFactory, EffectHandler } | ||
export { | ||
withEffects, | ||
ObservableComponent, | ||
EffectFactory, | ||
EffectHandler, | ||
ObserveOptions | ||
} |
import $$observable from 'symbol-observable' | ||
const fromObs = require('callbag-from-obs') | ||
const toObs = require('callbag-to-obs') | ||
import { ObserveOptions } from './baseTypes' | ||
@@ -25,3 +26,6 @@ export interface Callbag<I, O> { | ||
export interface ObservableComponent { | ||
observe: <T = any>(propName: string) => Source<T> | ||
observe: <T = any>( | ||
propName: string, | ||
options: Partial<ObserveOptions> | ||
) => Source<T> | ||
mount: Source<any> | ||
@@ -28,0 +32,0 @@ unmount: Source<any> |
import * as React from 'react' | ||
import { PropListeners, Listeners, EffectHandler } from './baseTypes' | ||
import { | ||
PropListeners, | ||
Listeners, | ||
EffectHandler, | ||
ObserveOptions | ||
} from './baseTypes' | ||
import { | ||
Subscription, | ||
@@ -55,3 +60,10 @@ Listener, | ||
const createPropObservable = <T>(propName: string) => { | ||
const createPropObservable = <T>( | ||
propName: string, | ||
opts: Partial<ObserveOptions> | ||
) => { | ||
const options: ObserveOptions = { | ||
initialValue: true, | ||
...opts | ||
} | ||
const listenerType = | ||
@@ -67,2 +79,6 @@ typeof this.props[propName] === 'function' | ||
if (listenerType === 'props' && options.initialValue) { | ||
listener.next(this.props[propName]) | ||
} | ||
return () => { | ||
@@ -79,4 +95,6 @@ this.listeners[listenerType][propName].filter( | ||
unmount: unmountObservable, | ||
observe: <T>(propName: string) => | ||
createPropObservable<T>(propName) | ||
observe: <T>( | ||
propName: string, | ||
options: Partial<ObserveOptions> | ||
) => createPropObservable<T>(propName, options) | ||
} | ||
@@ -91,4 +109,2 @@ | ||
) | ||
this.sendNext() | ||
} | ||
@@ -95,0 +111,0 @@ |
@@ -12,1 +12,4 @@ import { Listener } from './observable' | ||
export declare type EffectHandler<P, E> = (intialProps: P) => (val: E) => void | ||
export interface ObserveOptions { | ||
initialValue: boolean | ||
} |
import { withEffects } from './withEffects' | ||
import { ObservableComponent, EffectFactory } from './observable' | ||
import { EffectHandler } from './baseTypes' | ||
export { withEffects, ObservableComponent, EffectFactory, EffectHandler } | ||
import { EffectHandler, ObserveOptions } from './baseTypes' | ||
export { | ||
withEffects, | ||
ObservableComponent, | ||
EffectFactory, | ||
EffectHandler, | ||
ObserveOptions | ||
} |
@@ -0,1 +1,2 @@ | ||
import { ObserveOptions } from './baseTypes' | ||
export interface Callbag<I, O> { | ||
@@ -17,3 +18,6 @@ (t: 0, d: Callbag<O, I>): void | ||
export interface ObservableComponent { | ||
observe: <T = any>(propName: string) => Source<T> | ||
observe: <T = any>( | ||
propName: string, | ||
options: Partial<ObserveOptions> | ||
) => Source<T> | ||
mount: Source<any> | ||
@@ -20,0 +24,0 @@ unmount: Source<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
27732
681