diff --git a/src/client/effects.js b/src/client/effects.js new file mode 100644 index 0000000..02a61be --- /dev/null +++ b/src/client/effects.js @@ -0,0 +1,2 @@ +export default { +}; diff --git a/src/client/middleware.js b/src/client/middleware.js new file mode 100644 index 0000000..bf12960 --- /dev/null +++ b/src/client/middleware.js @@ -0,0 +1,9 @@ +import effects from './effects'; + +export default (store) => (next) => (action) => { + const result = next(action); + if (effects[action.type]) { + setTimeout(() => effects[action.type](store, action), 0); + } + return result; +}; diff --git a/src/client/resource-from-uri.js b/src/client/resource-from-uri.js index 2751ab4..b63ad78 100644 --- a/src/client/resource-from-uri.js +++ b/src/client/resource-from-uri.js @@ -2,4 +2,4 @@ import {all} from './resources.scwp'; const resources = Object.values(all()).map((M) => M.default); -export default (uri) => resources.find((resource) => uri.match(resource.matcher)); +export default (uri) => resources.find((resource) => resource.matcher(uri)); diff --git a/src/client/sidebar.jsx b/src/client/sidebar.jsx index ac9bf95..3474b92 100644 --- a/src/client/sidebar.jsx +++ b/src/client/sidebar.jsx @@ -43,7 +43,7 @@ const mapComponents = (tree) => tree.map((node) => { node.uri ? 'resource' : 'directory', )} > - {node.uri && } + {node.uri && resource && } {node.title} ), diff --git a/src/client/store.js b/src/client/store.js index 59362da..96670ab 100644 --- a/src/client/store.js +++ b/src/client/store.js @@ -8,6 +8,7 @@ import {all} from './resources.scwp'; import appReducer from './state'; const resources = Object.values(all()).map((M) => M.default); + const reducerMap = resources.reduce( (r, {keys, state: {default: reducer}}) => ({...r, [keys[1]]: reducer}), {}, diff --git a/src/common/resources/entity/entity.resource.js b/src/common/resources/entity/entity.resource.js index 1a8ba59..3d4cf2d 100644 --- a/src/common/resources/entity/entity.resource.js +++ b/src/common/resources/entity/entity.resource.js @@ -1,10 +1,11 @@ import EntityComponent from './entity'; import Icon from './icon'; +import matcher from './matcher'; export default { keys: ['entity', 'entities'], Icon, - matcher: /\.entity\.json$/, + matcher, Component: EntityComponent, // eslint-disable-next-line global-require state: require('./state'), diff --git a/src/common/resources/entity/matcher.js b/src/common/resources/entity/matcher.js new file mode 100644 index 0000000..5ace8fc --- /dev/null +++ b/src/common/resources/entity/matcher.js @@ -0,0 +1 @@ +export default (uri) => uri.match(/\.entity\.json$/); diff --git a/src/common/resources/entity/state.js b/src/common/resources/entity/state.js index 913ef4a..17b0a63 100644 --- a/src/common/resources/entity/state.js +++ b/src/common/resources/entity/state.js @@ -10,6 +10,10 @@ import { createSlice, } from '@reduxjs/toolkit'; +import {closeResource} from '~/client/state'; + +import matcher from './matcher'; + const entitySchema = new schema.Entity('entities', {}, {idAttribute: 'uuid'}); const mergeEntityWithDefaults = (entity) => ( @@ -90,6 +94,12 @@ const slice = createSlice({ // eslint-disable-next-line no-return-assign .forEach(([id, entity]) => state.uris[entity.uri] = id); }, + [closeResource]: (state, {payload: uri}) => { + if (matcher(uri)) { + adapter.removeOne(state, state.uris[uri]); + delete state.uris[uri]; + } + }, }, });