Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

effector

Package Overview
Dependencies
Maintainers
1
Versions
272
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

effector - npm Package Compare versions

Comparing version 0.7.3 to 0.7.4

6

es/domain.js
import { from } from 'most';
import { async as subject } from 'most-subject';
import { PING, PONG } from './config';
import { port } from './port';
import { safeDispatch } from './port';
import { EventConstructor } from './event';

@@ -74,3 +74,5 @@ import { EffectConstructor } from './effect';

port(events$) {
port(dispatch, state$, events$);
return events$.observe(data => {
safeDispatch(data, dispatch);
});
},

@@ -77,0 +79,0 @@

@@ -119,3 +119,5 @@ import { async as subject } from 'most-subject';

effect.watch = watch;
effect.epic = port(dispatch, state$, action$);
effect.epic = port(dispatch, state$, action$); // effect.port = function port<R>(events$: Stream<R>) {
// return events$.observe(data => safeDispatch(data, dispatch))
// }

@@ -122,0 +124,0 @@ effect.subscribe = subscriber => action$.subscribe(subscriber);

// import type {Store} from 'redux'
import { async as subject } from 'most-subject';
import { nextPayloadID } from './id';
import { port } from './port';
import { port, safeDispatch } from './port';
import { basicCommon, observable } from './event-common';

@@ -63,4 +63,7 @@ export function EventConstructor(domainName, dispatch, getState, state$, events, name, action$ = subject()) {

eventInstance.subscribe = subscriber => action$.subscribe(subscriber);
eventInstance.subscribe = subscriber => action$.subscribe(subscriber); // eventInstance.port = function port<R>(events$: Stream<R>) {
// return events$.observe(data => safeDispatch(data, dispatch))
// }
observable(eventInstance, action$);

@@ -67,0 +70,0 @@ events.set(getType(), eventInstance);

@@ -28,3 +28,3 @@ function normalizeType(typeOrActionCreator) {

function reset(typeOrActionCreator) {
on(typeOrActionCreator, () => opts.defaultState);
on(typeOrActionCreator, (state, payload, meta) => opts.defaultState);
return returnType;

@@ -31,0 +31,0 @@ }

@@ -89,3 +89,5 @@ "use strict";

port(events$) {
(0, _port.port)(dispatch, state$, events$);
return events$.observe(data => {
(0, _port.safeDispatch)(data, dispatch);
});
},

@@ -92,0 +94,0 @@

@@ -131,3 +131,5 @@ "use strict";

effect.watch = watch;
effect.epic = (0, _port.port)(dispatch, state$, action$);
effect.epic = (0, _port.port)(dispatch, state$, action$); // effect.port = function port<R>(events$: Stream<R>) {
// return events$.observe(data => safeDispatch(data, dispatch))
// }

@@ -134,0 +136,0 @@ effect.subscribe = subscriber => action$.subscribe(subscriber);

@@ -74,4 +74,7 @@ "use strict";

eventInstance.subscribe = subscriber => action$.subscribe(subscriber);
eventInstance.subscribe = subscriber => action$.subscribe(subscriber); // eventInstance.port = function port<R>(events$: Stream<R>) {
// return events$.observe(data => safeDispatch(data, dispatch))
// }
(0, _eventCommon.observable)(eventInstance, action$);

@@ -78,0 +81,0 @@ events.set(getType(), eventInstance);

@@ -35,3 +35,3 @@ "use strict";

function reset(typeOrActionCreator) {
on(typeOrActionCreator, () => opts.defaultState);
on(typeOrActionCreator, (state, payload, meta) => opts.defaultState);
return returnType;

@@ -38,0 +38,0 @@ }

{
"name": "effector",
"version": "0.7.3",
"version": "0.7.4",
"description": "Redux effects",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -6,3 +6,2 @@ //@flow

applyMiddleware,
type Store,
type Reducer,

@@ -12,4 +11,11 @@ type Middleware,

} from 'redux'
import {from} from 'most'
import {createDomain, type Domain, type Event, rootDomain, effectorMiddleware} from '..'
import {from, periodic} from 'most'
import {
createDomain,
type Store,
type Event,
type Domain,
rootDomain,
effectorMiddleware,
} from '..'

@@ -22,5 +28,3 @@ test('smoke', async() => {

(s, x) => (fn(x), console.log(x), s),
applyMiddleware(
effectorMiddleware
)
applyMiddleware(effectorMiddleware),
)

@@ -49,5 +53,3 @@ const domain = createDomain(store)

(s, x) => (fn(x), console.log(x), s),
applyMiddleware(
effectorMiddleware
)
applyMiddleware(effectorMiddleware),
)

@@ -60,7 +62,3 @@ const domain = createDomain(store)

const event: Event<'ev', {foo: 'bar'}> = domain.event('event1')
event.epic(
data$ => data$.map(
effect
)
)
event.epic(data$ => data$.map(effect))
await event('ev').send()

@@ -71,2 +69,29 @@ expect(used).toHaveBeenCalledTimes(1)

test('port', async() => {
const fn = jest.fn()
const used = jest.fn((state, x) => console.log(x, state))
const usedEff = jest.fn((state, x) => console.log(x, state))
const store: Store<{foo: 'bar'}> = createStore(
(s, x) => (fn(x), console.log(x), s),
applyMiddleware(effectorMiddleware),
)
const domain: Domain<{ foo: 'bar' }> = createDomain(store)
const event = domain.event('port-event')
const eff = domain.event('port-effect')
event.watch(used)
eff.watch(usedEff)
const str$ = periodic(100)
.scan((a, b) => a + b, 0)
.take(10)
// .map(event)
domain.port(str$.map(event))
await new Promise(rs => setTimeout(rs, 1500))
expect(used).toHaveBeenCalledTimes(10)
domain.port(str$.map(eff))
await new Promise(rs => setTimeout(rs, 1500))
expect(usedEff).toHaveBeenCalledTimes(10)
})
test('both return and send', async() => {

@@ -78,9 +103,6 @@ const fn = jest.fn()

(s, x) => (fn(x), console.log(x), s),
applyMiddleware(
effectorMiddleware
)
applyMiddleware(effectorMiddleware),
)
const domain = rootDomain()
const effect = domain.effect('eff')

@@ -90,7 +112,3 @@ effect.use(used)

const event: Event<'ev', {foo: 'bar'}> = domain.event('event1')
event.epic(
data$ => data$.map(
e => effect(e).send()
)
)
event.epic(data$ => data$.map(e => effect(e).send()))
domain.register(store)

@@ -107,5 +125,3 @@ await event('ev').send()

(s, x) => (fn(x), console.log(x), s),
applyMiddleware(
effectorMiddleware
)
applyMiddleware(effectorMiddleware),
)

@@ -116,3 +132,7 @@ const domain = createDomain(store, 'with-prefix')

expect(event.getType()).toBe('TYPE_CONST')
event.epic(data$ => data$.map(e => { used(e) }))
event.epic(data$ =>
data$.map(e => {
used(e)
}),
)

@@ -132,5 +152,3 @@ console.log(event)

(s, x) => s,
applyMiddleware(
effectorMiddleware
)
applyMiddleware(effectorMiddleware),
)

@@ -137,0 +155,0 @@ const domain = createDomain(store)

@@ -28,4 +28,4 @@ // @flow

.reset(reset)
const state1 = reducer(undefined, event1('ev').raw())
const none: any = undefined
const state1 = reducer(none, event1('ev').raw())
expect(state1).toMatchSnapshot()

@@ -43,3 +43,3 @@ const state2 = reducer(state1, event2('ev2').raw())

const event3: Event<'ev3', State> = domain.event('event3')
const reset: Event<void, State> = domain.event('reset')
const reset: Event<mixed, State> = domain.event('reset')

@@ -56,3 +56,3 @@ const reducerA: Reducer<{

}> = createReducer({resets: 0})
.on(reset, (state, payload) => ({
.on(reset, (state) => ({
resets: state.resets + 1,

@@ -72,5 +72,7 @@ }))

}))
const state1 = union(undefined, event1('ev').raw())
.on(event2, (e, event) => e)
const none: any = undefined
const state1 = union(none, event1('ev').raw())
expect(state1).toMatchSnapshot()
const state2 = union(state1, reset().raw())
const state2 = union(state1, reset('').raw())
expect(state2).toMatchSnapshot()

@@ -77,0 +79,0 @@ const state3 = union(state2, event2('ev2').raw())

@@ -11,3 +11,3 @@ //@flow

import {port} from './port'
import {safeDispatch} from './port'
import {EventConstructor} from './event'

@@ -106,4 +106,4 @@ import {EffectConstructor} from './effect'

return {
port<R>(events$: Stream<R>) {
port(dispatch, state$, events$)
port<R>(events$: Stream<R>): Promise<void> {
return events$.observe(data => { safeDispatch(data, dispatch) })
},

@@ -110,0 +110,0 @@ register(store) {

@@ -134,2 +134,5 @@ //@flow

effect.epic = port(dispatch, state$, action$)
// effect.port = function port<R>(events$: Stream<R>) {
// return events$.observe(data => safeDispatch(data, dispatch))
// }
effect.subscribe = (subscriber) => action$.subscribe(subscriber)

@@ -136,0 +139,0 @@ observable(effect, action$)

@@ -11,3 +11,3 @@ //@flow

import {port} from './port'
import {port, safeDispatch} from './port'

@@ -75,2 +75,5 @@ import {basicCommon, observable} from './event-common'

eventInstance.subscribe = (subscriber) => action$.subscribe(subscriber)
// eventInstance.port = function port<R>(events$: Stream<R>) {
// return events$.observe(data => safeDispatch(data, dispatch))
// }
observable(eventInstance, action$)

@@ -77,0 +80,0 @@ events.set(getType(), eventInstance)

@@ -7,9 +7,13 @@ //@flow

type Handler<S, P, M={}> = (state: S, payload: P, meta?: M) => S
type Handler<S, P> = (state: S, payload: P, meta: {
index: ID,
eventID: ID,
seq: ID,
}) => S
export type Store<S> = {
dispatch: <T>(x: T) => T,
dispatch: Function,
getState(): S,
subscribe(listener: any): () => void,
replaceReducer(nextReducer: Reducer<S>): void,
replaceReducer(nextReducer: (state: S, action: any) => S): void,
}

@@ -39,3 +43,3 @@

register: (store: Store<State>) => void,
port<R>(events$: Stream<R>): void,
port<R>(events$: Stream<R>): Promise<void>,
}

@@ -67,2 +71,3 @@

subscribe(subscriber: Subscriber<Payload>): Subscription<Payload>,
// port<R>(events$: Stream<R>): Promise<void>,
}

@@ -86,2 +91,3 @@

): Stream<R>,
// port<R>(events$: Stream<R>): Promise<void>,
use(thunk: (params: Params) => Promise<Done>): void,

@@ -94,9 +100,13 @@ subscribe(subscriber: Subscriber<Params>): Subscription<Params>,

export type Reducer<S> = {
(state?: S, action: RawAction<any>): S,
(state: S, action: RawAction<any>): S,
options(opts: { fallback: boolean }): Reducer<S>,
has(event: Event<any, any>): boolean,
on<
P, M,
P,
A/*: Event<P, any> | $ReadOnlyArray<Event<any, any>>*/
>(event: A, handler: (state: S, payload: P, meta?: M) => S): Reducer<S>,
>(event: A, handler: (state: S, payload: P, meta: {
index: ID,
eventID: ID,
seq: ID,
}) => S): Reducer<S>,
off<

@@ -111,11 +121,11 @@ A/*: Event<any, any> | $ReadOnlyArray<Event<any, any>>*/

export type Handlers<S> = {
[propertyName: string]: Handler<S, any, any>
[propertyName: string]: Handler<S, any>
}
type functionOn<S, P, M={}> = (actionCreator: Event<P, any>, handler: Handler<S, P, M>) => Reducer<S>
type functionOn<S, P> = (actionCreator: Event<P, any>, handler: Handler<S, P>) => Reducer<S>
type functionOff<S> = (actionCreator: Event<any, any>) => Reducer<S>
export type OnOff<S> = {
(on: functionOn<S, any, any>, off: functionOff<S>): void;
(on: functionOn<S, any>, off: functionOff<S>): void;
}
//@flow
export type {Event, Effect, Domain, Reducer} from './index.h'
export type {Event, Effect, Domain, Reducer, Store} from './index.h'
export {createDomain, rootDomain} from './domain'

@@ -5,0 +5,0 @@ export {effectorMiddleware} from './middleware'

@@ -13,6 +13,6 @@ //@noflow

const defaultValues = [...values]
const defaultState: C = combine(...values)
let lastState: C = defaultState
const defaultState: R = combine(...values)
let lastState: R = defaultState
const combined = createReducer(defaultState, {}, combinedReducer)
function combinedReducer(state, action): C {
function combinedReducer(state, action): R {
const changed: Set<number> = new Set()

@@ -19,0 +19,0 @@ for (let i = 0; i < reducers.length; i++) {

@@ -22,3 +22,6 @@ // @flow

): Reducer<S> {
const opts = {
const opts: {
defaultState: S,
fallback: null | (state: S, payload: any, meta: *) => S
} = {
fallback: null,

@@ -40,3 +43,3 @@ defaultState,

function reset(typeOrActionCreator) {
on(typeOrActionCreator, () => opts.defaultState)
on(typeOrActionCreator, (state: S, payload: any, meta: *) => opts.defaultState)
return returnType

@@ -43,0 +46,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

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

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

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

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

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

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc