Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const todos: TodosModel = {
items: [],
add: action((state, payload) => {
state.items.push(payload);
}),
clear: action(state => {
state.items = [];
}),
};
const model: Model = {
todos,
};
const store = createStore(model);
store.dispatch.todos.add('foo');
// typings:expect-error
store.dispatch.todos.add(1);
// typings:expect-error
store.dispatch.todos.add();
store.dispatch.todos.clear();
interface ListeningModel {
logs: string[];
}
interface TargetModel {
doAction: Action;
doThunk: Thunk;
injections.fetch().then(() => 'done');
dispatch({ type: 'FOO' });
getStoreActions().audit.log('foo');
meta.parent.concat(['foo']);
meta.path.concat(['foo']);
return 1;
},
),
syncThunk: thunk((actions, payload) => {
return 'Woot!';
}),
empty: thunk(() => {}),
},
};
const store = createStore(model);
store
.getActions()
.audit.syncThunk()
.toUpperCase();
store
.getActions()
.audit.log('foo')
.then(result => result + 1);
// typings:expect-error
store.getActions().audit.log(1);
// typings:expect-error
store.getActions().audit.log();
store.getActions().audit.empty();
// typings:expect-error
interface PersistPartial {
persist: string;
}
function persistReducer(
baseReducer: Reducer,
): Reducer<s> {
return (baseReducer as unknown) as Reducer<s>;
}
const store = createStore(model, {
reducerEnhancer: reducer => persistReducer(reducer),
});
const configuredStore = createStore(model, {
disableImmer: false,
devTools: false,
initialState: { foo: 'bar' },
injections: { foo: 'bar' },
mockActions: true,
name: 'bob',
reducerEnhancer: reducer => reducer,
});
store.getActions().doActionVoid();
store.getActions().doAction(true);
store.dispatch.doAction(true);
// typings:expect-error
store.getActions().doAction(1);</s></s>
return items.length;
}),
getById: selector([state => state.items], ([items], [id]) => {
return items.find(x => x.id === id);
}),
unTypedArgs: selector([state => state.items], ([items]) => items.length),
},
status: {
totalTodos: selector(
[(state, storeState) => storeState.todos.count],
([count]) => count(),
),
},
};
const store = createStore(model);
const count = store.getState().todos.count();
count + 1;
// typings:expect-error
store.getState().todos.getById();
// typings:expect-error
store.getState().todos.getById('foo');
const todo = store.getState().todos.getById(1);
// typings:expect-error
todo.text + 'foo';
import { composeWithDevTools } from 'redux-devtools-extension';
import { createStore } from 'easy-peasy';
import { model } from './models';
/**
* model, is used for passing through the base model
* the second argument takes an object for additional configuration
*/
const store = createStore(model, {
compose: composeWithDevTools({ realtime: true, trace: true })
// initialState: {}
});
export default store;
beforeEach(() => {
// reset the store before each test run
store = createStore(rootModel, { injections });
});
designer: designerModel,
};
const network = getNetwork();
const initialState = {
network: {
networks: [network],
},
designer: {
activeId: 1,
allCharts: {
1: initChartFromNetwork(network),
},
},
};
// initialize store for type inference
let store = createStore(rootModel, { injections, initialState });
const node = initialState.network.networks[0].nodes.lightning[0] as LndNode;
beforeEach(() => {
// reset the store before each test run
store = createStore(rootModel, { injections, initialState });
asyncUtilMock.delay.mockResolvedValue(Promise.resolve());
bitcoindServiceMock.sendFunds.mockResolvedValue('txid');
lightningServiceMock.getNewAddress.mockResolvedValue({ address: 'bc1aaaa' });
lightningServiceMock.getInfo.mockResolvedValue(
defaultStateInfo({
alias: 'my-node',
pubkey: 'abcdef',
syncedToChain: true,
}),
);
interface IModel {
animal: IAnimal;
setAnimal: Action;
}
const model: IModel = {
animal: {
name: 'robert',
},
setAnimal: action((state, payload) => {
return { ...state, animal: payload.animal };
}),
};
const store = createStore(model);
import user, { UserStore } from '@/state/user';
import permissions, { GloablPermissionsStore } from '@/state/permissions';
export interface ApplicationStore {
permissions: GloablPermissionsStore;
flashes: FlashStore;
user: UserStore;
}
const state: ApplicationStore = {
permissions,
flashes,
user,
};
export const store = createStore(state);
}
const buttons = [...document.querySelectorAll('.moltin-buy-button')]
const cartBtns = [...document.querySelectorAll('.moltin-cart-button')]
const loginBtns = [...document.querySelectorAll('.moltin-login-button')]
const cart = document.createElement('div')
document.body.appendChild(cart)
const api = new MoltinClient({
client_id,
application: 'moltin-btn',
...(currency && { currency })
})
const store = createStore(model, {
injections: {
api
}
})
buttons.forEach(el =>
ReactDOM.render(
,
el
)
)