Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{ setState }: StoreActionApi,
{ defaultColor }: ContainerProps
) => {
setState({
color: value || defaultColor,
});
},
};
const Store = createStore({
name: 'theme',
initialState,
actions,
});
export const ThemeContainer = createContainer(
Store,
{
onInit: () => ({ getState, dispatch }) => {
// this gets currently called also when component remounts
// so it is important to check state status and apply default only on first mount
const { color } = getState();
if (!color) {
dispatch(actions.change());
}
},
}
);
export const ThemeSubscriber = createSubscriber(Store);
export const useTheme = createHook(Store);
[todo.id]: { ...todo, isDone: !todo.isDone },
},
});
},
};
const Store = createStore({
name: 'todos',
initialState,
actions,
});
/** Container */
type ContainerProps = {| n: number |};
export const TodosContainer = createContainer(
Store,
{
onInit: () => ({ getState, dispatch }, { n }) => {
if (getState().order.length) return;
Array.from({ length: 10 * n }).map((__, i) => {
const title = `Todo ${n}-${i + 1}`;
dispatch(actions.add(title));
});
},
}
);
/** Subscribers / Hooks */
const getAllTodosSelector = state => ({
data: state.order.map(v => state.byId[v]),
await new Promise(r => setTimeout(r, 1000));
setState({
isSending: false,
message: '',
});
return message;
},
};
const Store = createStore({
name: 'form',
initialState,
actions,
});
export const FormContainer = createContainer(
Store,
{
onUpdate: () => ({ setState }, { remoteUsers }) => {
setState({ toUsers: remoteUsers });
},
}
);
export const FormSubscriber = createSubscriber(Store);
export const useForm = createHook(Store);
export const FormActions = createSubscriber(Store, {
selector: null,
});
import * as actions from './actions';
type Actions = typeof actions;
type ContainerProps = {| selectedUser: string | null |};
const initialState: State = {
data: null,
loading: false,
};
const Store = createStore({
initialState,
actions,
});
export const TodoContainer = createContainer(
Store,
{
onUpdate: () => ({ dispatch }, { selectedUser }) => {
if (selectedUser) dispatch(actions.load(selectedUser));
},
}
);
export const TodoSubscriber = createSubscriber(Store);
export const useTodo = createHook(Store);
type Actions = typeof actions;
type ContainerProps = {||};
type UserSelectedState = $Call;
const initialState: State = {
selected: null,
data: null,
loading: false,
};
const Store = createStore({
initialState,
actions,
});
export const UserContainer = createContainer(
Store,
{
onInit: actions.load,
}
);
export const UserSubscriber = createSubscriber(Store);
export const UserSelectedSubscriber = createSubscriber<
State,
Actions,
UserSelectedState,
void
>(Store, {
selector: selectors.getSelected,
});