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 SimpleModelReducer = (
state: ISimpleModel = initSimpleModel(),
action: any
) => {
return immer.produce(state, (draft: ISimpleModel) => {
switch (action.type) {
case SimpleModelEnums.SimpleModel_items:
new RSimpleModel(draft).items = action.payload;
break;
}
});
};
/********************************
rotate() {
const nextState = immer.produce(this.state, (draft: ITetrisModel) =>
new RTetrisModel(draft).rotate()
);
if (this.__devTools) {
this.__devTools.send("rotate", nextState);
}
this.setStateSync(nextState);
}
step() {
export const TestModelReducer = (state:ITestModel = init_TestModel(), action) => {
return immer.produce(state, draft => {
switch (action.type) {
case TestModelEnums.TestModel_items:
(new RTestModel(draft)).items = action.payload
break;
case TestModelEnums.TestModel_maxId:
(new RTestModel(draft)).maxId = action.payload
break;
case TestModelEnums.TestModel_shopState:
(new RTestModel(draft)).shopState = action.payload
break;
case TestModelEnums.TestModel_add:
(new RTestModel(draft)).add(action.payload)
break;
}
})
}
export const TodoListReducer = (state:ITodoList = init_TodoList(), action) => {
return immer.produce(state, draft => {
switch (action.type) {
case TodoListEnums.TodoList_items:
(new RTodoList(draft)).items = action.payload
break;
case TodoListEnums.TodoList_state:
(new RTodoList(draft)).state = action.payload
break;
}
})
}
setTitle(value: string) {
const nextState = immer.produce(this.state, draft =>
new RTodoList(draft).setTitle(value)
);
if (this.__devTools) {
this.__devTools.send("setTitle", nextState);
}
this.setStateSync(nextState);
}
addLotOfItems(cnt: number) {
if (selectedPlugin) {
performance.mark(`activePlugin-${selectedPlugin}`);
}
return updateSelection({
...state,
staticView: null,
selectedApp: selectedApp || null,
selectedPlugin,
userPreferredPlugin: selectedPlugin || state.userPreferredPlugin,
});
}
case 'STAR_PLUGIN': {
const {selectedPlugin, selectedApp} = action.payload;
return produce(state, draft => {
if (!draft.userStarredPlugins[selectedApp]) {
draft.userStarredPlugins[selectedApp] = [selectedPlugin];
} else {
const plugins = draft.userStarredPlugins[selectedApp];
const idx = plugins.indexOf(selectedPlugin);
if (idx === -1) {
plugins.push(selectedPlugin);
} else {
plugins.splice(idx, 1);
}
}
});
}
case 'SELECT_USER_PREFERRED_PLUGIN': {
const {payload} = action;
set: fn => set(produce(fn))
}))
export const useSuperReducer = (reducers, initialState, id) => {
const reducer = useCallback(
(state, action) => {
if (!reducers[action.type]) {
throw new Error(`unknown action ${action.type}`)
}
return reducers[action.type](state, action)
},
[reducers]
)
const cachedImmerReducer = useCallback(produce(reducer), [reducer])
const [reducerState, setReducerState] = useState(initialState, id)
const state = useRef(reducerState)
const getState = () => state.current
const setState = newState => {
state.current = newState
setReducerState(newState)
}
const reduce = action => cachedImmerReducer(getState(), action)
const dispatchWithSideEffects = action =>
typeof action === 'function'
? action(dispatchWithSideEffects, getState)
: setState(reduce(action))
export async function run(options, done) {
if (!options.repo && !options.all) {
logger.error('You must specify a Git repository with a GitHub remote to run this command')
}
if (!userRanValidFlags(DETAILS.commands, options)) {
const payload = options.argv.remain && options.argv.remain.concat().slice(1)
options = produce(options, draft => {
if (payload && payload[0]) {
draft.fetch = true
} else {
draft.list = true
}
})
}
const numbers = [...options.number]
for (const number of numbers) {
await main(number, options)
}
done && done()
onClick={(e) => {
e.stopPropagation();
e.preventDefault();
this.handleCloseMore(
produce(logOptions, (draft) => {
draft[option.key] = !logOptions[option.key];
}),
);
}}
>