New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@zuze/modifiable-effects

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zuze/modifiable-effects

Simple side effects helper for @zuze/modifiable

latest
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

modifiable-effects

npm version Coverage Status Build Status Bundle Phobia

Side Effects

Simple side-effects implementation for a modifiable.

Given a modifiable, an effect is just a plain modifier that returns the identity function, so you can do this:

import { effect } from '@zuze/modiable-effects',
import { modifiable } from '@zuze/modifiable';

const myEffect1 = async (context,setContext,getState) => { ... }
const myEffect2 = async (context,setContext,getState) => { ... }

const m = modifiable(initialState,{
    modifiers:[
        effect(myEffect1),
        [ effect(myEffect2), 'dep1', 'dep2', ({dep3}) => dep3[0] ],
        ...otherModifiers
    ]
});

Or you can use the default export function that accepts a

import withEffects from '@zuze/modifiable-effects';
import { modifiable } from '@zuze/modifiable';

const m = modifiable(...);

const myEffect = async => (context,setContext,getState) => {
    try {
        await someAsyncCall();
        setContext({...})
    } catch(err) {
        setContext({...})
    }
};

const myEffect2 = async => ...

const removeEffect = withEffects(modifiable, myEffect, myEffect2, ...otherEffects);

// returns a function that accepts a function reference and removes a side effect
removeEffect(myEffect);

With Dependencies

import withEffects from '@zuze/modifiable-effects';
import { modifiable } from '@zuze/modifiable';

const m = modifiable(...);

const myEffect = [async (context,setContext,getState) => {
    try {
        await someAsyncCall();
        setContext({...})
    } catch(err) {
        setContext({...})
    }
// this effect will run only when context changes 
}, ['dep1', 'dep2', ({dep3}) => dep3[0] ]

withEffects(modifiable,myEffect);

Keywords

modifiable

FAQs

Package last updated on 02 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts