refract-redux-callbag
Advanced tools
Comparing version 1.0.0-0 to 1.0.0-1
@@ -33,8 +33,8 @@ import $$observable from 'symbol-observable'; | ||
var storeObservable = fromObs(store); | ||
return function (actionOrSelector, withInitialValue) { | ||
if (withInitialValue === void 0) { withInitialValue = true; } | ||
return function (actionOrSelector, opts) { | ||
var options = __assign({ initialValue: true }, opts); | ||
if (typeof actionOrSelector === 'string') { | ||
return fromObs((_a = { | ||
subscribe: function (listener) { | ||
var unsubscribe = store.addActionListener(actionOrSelector); | ||
var unsubscribe = store.addActionListener(actionOrSelector, listener.next.bind(listener)); | ||
return { unsubscribe: unsubscribe }; | ||
@@ -49,3 +49,9 @@ } | ||
if (typeof actionOrSelector === 'function') { | ||
return pipe(map(actionOrSelector), startWith(actionOrSelector(store.getState())), dropRepeats()); | ||
var operators = [ | ||
map(actionOrSelector), | ||
options.initialValue && | ||
startWith(actionOrSelector(store.getState())), | ||
dropRepeats() | ||
].filter(Boolean); | ||
return pipe.apply(void 0, [storeObservable].concat(operators)); | ||
} | ||
@@ -52,0 +58,0 @@ var _a; |
14
index.js
@@ -39,8 +39,8 @@ 'use strict'; | ||
var storeObservable = fromObs(store); | ||
return function (actionOrSelector, withInitialValue) { | ||
if (withInitialValue === void 0) { withInitialValue = true; } | ||
return function (actionOrSelector, opts) { | ||
var options = __assign({ initialValue: true }, opts); | ||
if (typeof actionOrSelector === 'string') { | ||
return fromObs((_a = { | ||
subscribe: function (listener) { | ||
var unsubscribe = store.addActionListener(actionOrSelector); | ||
var unsubscribe = store.addActionListener(actionOrSelector, listener.next.bind(listener)); | ||
return { unsubscribe: unsubscribe }; | ||
@@ -55,3 +55,9 @@ } | ||
if (typeof actionOrSelector === 'function') { | ||
return pipe(map(actionOrSelector), startWith(actionOrSelector(store.getState())), dropRepeats()); | ||
var operators = [ | ||
map(actionOrSelector), | ||
options.initialValue && | ||
startWith(actionOrSelector(store.getState())), | ||
dropRepeats() | ||
].filter(Boolean); | ||
return pipe.apply(void 0, [storeObservable].concat(operators)); | ||
} | ||
@@ -58,0 +64,0 @@ var _a; |
{ | ||
"name": "refract-redux-callbag", | ||
"version": "1.0.0-0", | ||
"version": "1.0.0-1", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "jsnext:main": "index.es.js", |
@@ -11,1 +11,5 @@ export interface EnhancerOptions { | ||
export type Selector<T> = (state: object) => T | ||
export interface ObserveOptions { | ||
initialValue: boolean | ||
} |
import refractEnhancer from './refractEnhancer' | ||
import { EnhancerOptions } from './baseTypes' | ||
import { EnhancerOptions, ObserveOptions } from './baseTypes' | ||
export { refractEnhancer, EnhancerOptions } | ||
export { refractEnhancer, EnhancerOptions, ObserveOptions } |
@@ -8,3 +8,3 @@ import $$observable from 'symbol-observable' | ||
import { Selector } from './baseTypes' | ||
import { Selector, ObserveOptions } from './baseTypes' | ||
@@ -14,3 +14,3 @@ export interface ObserveFn { | ||
actionTypeOrListener: string | Selector<T>, | ||
withInitialValue?: boolean | ||
options: Partial<ObserveOptions> | ||
): Source<T> | ||
@@ -39,4 +39,8 @@ } | ||
actionOrSelector: string | Selector<T>, | ||
withInitialValue = true | ||
opts: Partial<ObserveOptions> | ||
): Source<T> => { | ||
const options: ObserveOptions = { | ||
initialValue: true, | ||
...opts | ||
} | ||
if (typeof actionOrSelector === 'string') { | ||
@@ -46,3 +50,4 @@ return fromObs({ | ||
const unsubscribe = store.addActionListener( | ||
actionOrSelector | ||
actionOrSelector, | ||
listener.next.bind(listener) | ||
) | ||
@@ -59,9 +64,12 @@ | ||
if (typeof actionOrSelector === 'function') { | ||
return pipe( | ||
const operators = [ | ||
map(actionOrSelector), | ||
startWith(actionOrSelector(store.getState())), | ||
options.initialValue && | ||
startWith(actionOrSelector(store.getState())), | ||
dropRepeats() | ||
) | ||
].filter(Boolean) | ||
return pipe(storeObservable, ...operators) | ||
} | ||
} | ||
} |
@@ -11,1 +11,4 @@ export interface EnhancerOptions { | ||
export declare type Selector<T> = (state: object) => T | ||
export interface ObserveOptions { | ||
initialValue: boolean | ||
} |
import refractEnhancer from './refractEnhancer' | ||
import { EnhancerOptions } from './baseTypes' | ||
export { refractEnhancer, EnhancerOptions } | ||
import { EnhancerOptions, ObserveOptions } from './baseTypes' | ||
export { refractEnhancer, EnhancerOptions, ObserveOptions } |
@@ -1,6 +0,6 @@ | ||
import { Selector } from './baseTypes' | ||
import { Selector, ObserveOptions } from './baseTypes' | ||
export interface ObserveFn { | ||
<T>( | ||
actionTypeOrListener: string | Selector<T>, | ||
withInitialValue?: boolean | ||
options: Partial<ObserveOptions> | ||
): Source<T> | ||
@@ -7,0 +7,0 @@ } |
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
15761
399