mirror of
https://github.com/urbit/shrub.git
synced 2024-12-20 17:32:11 +03:00
js: added minimal graph-store reducer
This commit is contained in:
parent
7d74d1870f
commit
5b7a23ca30
43
pkg/interface/src/reducers/graph-update.js
Normal file
43
pkg/interface/src/reducers/graph-update.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
export default class GraphReducer {
|
||||||
|
reduce(json, state) {
|
||||||
|
const data = _.get(json, 'graph-update', false);
|
||||||
|
if (data) {
|
||||||
|
this.keys(data, state);
|
||||||
|
this.addGraph(data, state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
keys(json, state) {
|
||||||
|
const data = _.get(json, 'keys', false);
|
||||||
|
if (data) {
|
||||||
|
state.keys = data.map((res) => {
|
||||||
|
return res.ship + '/' + res.name;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addGraph(json, state) {
|
||||||
|
const data = _.get(json, 'add-graph', false);
|
||||||
|
if (data) {
|
||||||
|
if (!('graphs' in state)) {
|
||||||
|
state.graphs = {};
|
||||||
|
}
|
||||||
|
let resource = data.resource.ship + '/' + data.resource.name;
|
||||||
|
state.graphs[resource] = data.graph;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
removeGraph(json, state) {
|
||||||
|
const data = _.get(json, 'remove-graph', false);
|
||||||
|
if (data) {
|
||||||
|
if (!('graphs' in state)) {
|
||||||
|
state.graphs = {};
|
||||||
|
}
|
||||||
|
let resource = data.resource.ship + '/' + data.resource.name;
|
||||||
|
delete state.graphs[resource];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user