flow: close what you open

This commit is contained in:
cha0s 2020-06-28 22:12:59 -05:00
parent ded78eda67
commit 820d444019
8 changed files with 27 additions and 3 deletions

2
src/client/effects.js vendored Normal file
View File

@ -0,0 +1,2 @@
export default {
};

9
src/client/middleware.js Normal file
View File

@ -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;
};

View File

@ -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));

View File

@ -43,7 +43,7 @@ const mapComponents = (tree) => tree.map((node) => {
node.uri ? 'resource' : 'directory',
)}
>
{node.uri && <resource.Icon />}
{node.uri && resource && <resource.Icon />}
<span className="text">{node.title}</span>
</span>
),

View File

@ -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}),
{},

View File

@ -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'),

View File

@ -0,0 +1 @@
export default (uri) => uri.match(/\.entity\.json$/);

View File

@ -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];
}
},
},
});