2020-07-23 21:38:42 +02:00
|
|
|
import produce, { Draft, setAutoFreeze } from 'immer';
|
2020-07-22 20:03:31 +02:00
|
|
|
|
|
|
|
export const defaultState = {
|
|
|
|
watchedResources: {},
|
|
|
|
};
|
|
|
|
|
2020-07-23 21:38:42 +02:00
|
|
|
setAutoFreeze(false); // TODO: REMOVE ONCE PLUGIN BRANCH HAS BEEN MERGED!!
|
|
|
|
|
2020-07-22 20:03:31 +02:00
|
|
|
const reducer = produce((draft: Draft<any>, action:any) => {
|
|
|
|
if (action.type.indexOf('RESOURCE_EDIT_WATCHER_') !== 0) return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
switch (action.type) {
|
|
|
|
|
|
|
|
case 'RESOURCE_EDIT_WATCHER_SET':
|
|
|
|
|
|
|
|
draft.watchedResources[action.id] = {
|
|
|
|
id: action.id,
|
|
|
|
title: action.title,
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'RESOURCE_EDIT_WATCHER_REMOVE':
|
|
|
|
|
|
|
|
delete draft.watchedResources[action.id];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'RESOURCE_EDIT_WATCHER_CLEAR':
|
|
|
|
|
|
|
|
draft.watchedResources = {};
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
error.message = `In plugin reducer: ${error.message} Action: ${JSON.stringify(action)}`;
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default reducer;
|