Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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]),
loading: state.loading,
});
export const TodosSubscriber = createSubscriber(
Store,
{
selector: getAllTodosSelector,
}
);
export const useTodos = createHook(Store, {
selector: getAllTodosSelector,
});
const getTodosCountSelector = state => ({ count: state.order.length });
export const TodosCountSubscriber = createSubscriber(
Store,
{
selector: getTodosCountSelector,
});
export const TodosSubscriber = createSubscriber(
Store,
{
selector: getAllTodosSelector,
}
);
export const useTodos = createHook(Store, {
selector: getAllTodosSelector,
});
const getTodosCountSelector = state => ({ count: state.order.length });
export const TodosCountSubscriber = createSubscriber(
Store,
{
selector: getTodosCountSelector,
}
);
export const useTodosCount = createHook(Store, {
selector: getTodosCountSelector,
});
type TodosFilteredProps = {| isDone: boolean |};
const getFilteredTodosSelector = (state: State, props: TodosFilteredProps) => ({
data: state.order
.map(v => state.byId[v])
.filter(t => t.isDone === props.isDone),
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,
});
export const useFormActions = createHook(Store, {
selector: null,
});
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,
});
export const useUser = createHook(Store);
export const useUserSelected = createHook<
State,
Actions,
UserSelectedState,
void
>(Store, { selector: selectors.getSelected });
const actions = {
add: (message: string) => ({ setState, getState }: StoreActionApi) => {
setState({
data: [...getState().data, message],
});
},
};
const Store = createStore({
name: 'messages',
initialState,
actions,
});
export const MessagesSubscriber = createSubscriber(Store);
export const useMessages = createHook(Store);
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);
};
const actions = {
increment: () => ({ setState, getState }: StoreActionApi) => {
setState({
count: getState().count + 1,
});
},
};
const Store = createStore({
initialState,
actions,
});
export const CounterSubscriber = createSubscriber(Store);
export const useCounter = createHook(Store);
};
const actions = {
increment: () => ({ setState, getState }: StoreActionApi) => {
setState({
count: getState().count + 1,
});
},
};
const Store = createStore({
initialState,
actions,
});
export const CounterSubscriber = createSubscriber(Store);
export const useCounter = createHook(Store);
});
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,
});
export const useFormActions = createHook(Store, {
selector: null,
});