flow: close what you open
This commit is contained in:
parent
ded78eda67
commit
820d444019
2
src/client/effects.js
vendored
Normal file
2
src/client/effects.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
export default {
|
||||||
|
};
|
9
src/client/middleware.js
Normal file
9
src/client/middleware.js
Normal 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;
|
||||||
|
};
|
|
@ -2,4 +2,4 @@ import {all} from './resources.scwp';
|
||||||
|
|
||||||
const resources = Object.values(all()).map((M) => M.default);
|
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));
|
||||||
|
|
|
@ -43,7 +43,7 @@ const mapComponents = (tree) => tree.map((node) => {
|
||||||
node.uri ? 'resource' : 'directory',
|
node.uri ? 'resource' : 'directory',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{node.uri && <resource.Icon />}
|
{node.uri && resource && <resource.Icon />}
|
||||||
<span className="text">{node.title}</span>
|
<span className="text">{node.title}</span>
|
||||||
</span>
|
</span>
|
||||||
),
|
),
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {all} from './resources.scwp';
|
||||||
import appReducer from './state';
|
import appReducer from './state';
|
||||||
|
|
||||||
const resources = Object.values(all()).map((M) => M.default);
|
const resources = Object.values(all()).map((M) => M.default);
|
||||||
|
|
||||||
const reducerMap = resources.reduce(
|
const reducerMap = resources.reduce(
|
||||||
(r, {keys, state: {default: reducer}}) => ({...r, [keys[1]]: reducer}),
|
(r, {keys, state: {default: reducer}}) => ({...r, [keys[1]]: reducer}),
|
||||||
{},
|
{},
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import EntityComponent from './entity';
|
import EntityComponent from './entity';
|
||||||
import Icon from './icon';
|
import Icon from './icon';
|
||||||
|
import matcher from './matcher';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
keys: ['entity', 'entities'],
|
keys: ['entity', 'entities'],
|
||||||
Icon,
|
Icon,
|
||||||
matcher: /\.entity\.json$/,
|
matcher,
|
||||||
Component: EntityComponent,
|
Component: EntityComponent,
|
||||||
// eslint-disable-next-line global-require
|
// eslint-disable-next-line global-require
|
||||||
state: require('./state'),
|
state: require('./state'),
|
||||||
|
|
1
src/common/resources/entity/matcher.js
Normal file
1
src/common/resources/entity/matcher.js
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export default (uri) => uri.match(/\.entity\.json$/);
|
|
@ -10,6 +10,10 @@ import {
|
||||||
createSlice,
|
createSlice,
|
||||||
} from '@reduxjs/toolkit';
|
} from '@reduxjs/toolkit';
|
||||||
|
|
||||||
|
import {closeResource} from '~/client/state';
|
||||||
|
|
||||||
|
import matcher from './matcher';
|
||||||
|
|
||||||
const entitySchema = new schema.Entity('entities', {}, {idAttribute: 'uuid'});
|
const entitySchema = new schema.Entity('entities', {}, {idAttribute: 'uuid'});
|
||||||
|
|
||||||
const mergeEntityWithDefaults = (entity) => (
|
const mergeEntityWithDefaults = (entity) => (
|
||||||
|
@ -90,6 +94,12 @@ const slice = createSlice({
|
||||||
// eslint-disable-next-line no-return-assign
|
// eslint-disable-next-line no-return-assign
|
||||||
.forEach(([id, entity]) => state.uris[entity.uri] = id);
|
.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];
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user