mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-15 10:02:47 +03:00
graph-js: added demo fetch api / subscription objs
This commit is contained in:
parent
8d5fb16685
commit
7d74d1870f
@ -5,7 +5,7 @@ class PrivateHelper extends BaseApi {
|
|||||||
this.action('graph-store', 'graph-action', data);
|
this.action('graph-store', 'graph-action', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
addGraph(resource, graph) {
|
addGraph(resource = { ship: '~zod', name: 'asdf' }, graph = {}) {
|
||||||
this.graphAction({
|
this.graphAction({
|
||||||
'add-graph': {
|
'add-graph': {
|
||||||
resource,
|
resource,
|
||||||
@ -14,7 +14,7 @@ class PrivateHelper extends BaseApi {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
removeGraph(resource) {
|
removeGraph(resource = { ship: '~zod', name: 'asdf' }) {
|
||||||
this.graphAction({
|
this.graphAction({
|
||||||
'remove-graph': {
|
'remove-graph': {
|
||||||
resource
|
resource
|
||||||
@ -22,7 +22,7 @@ class PrivateHelper extends BaseApi {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addNodes(resource, nodes) {
|
addNodes(resource = { ship : '~zod', name: 'asdf' }, nodes = {}) {
|
||||||
this.graphAction({
|
this.graphAction({
|
||||||
'add-nodes': {
|
'add-nodes': {
|
||||||
resource,
|
resource,
|
||||||
@ -31,7 +31,7 @@ class PrivateHelper extends BaseApi {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
removeNodes(resource, indices) {
|
removeNodes(resource = { ship: '~zod', name: 'asdf' }, indices = []) {
|
||||||
this.graphAction({
|
this.graphAction({
|
||||||
'remove-nodes': {
|
'remove-nodes': {
|
||||||
resource,
|
resource,
|
||||||
@ -55,6 +55,15 @@ class PrivateHelper extends BaseApi {
|
|||||||
removeTag() {
|
removeTag() {
|
||||||
this.graphAction();
|
this.graphAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fetch(connection = 0) {
|
||||||
|
this.action('graph-view', 'graph-view-action', {
|
||||||
|
fetch: {
|
||||||
|
connection,
|
||||||
|
type: { all: null }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class GraphApi {
|
export default class GraphApi {
|
||||||
@ -64,6 +73,7 @@ export default class GraphApi {
|
|||||||
this.ship = ship;
|
this.ship = ship;
|
||||||
this.subscribe = helper.subscribe.bind(helper);
|
this.subscribe = helper.subscribe.bind(helper);
|
||||||
|
|
||||||
|
// store
|
||||||
this.addGraph = helper.addGraph.bind(helper);
|
this.addGraph = helper.addGraph.bind(helper);
|
||||||
this.removeGraph = helper.removeGraph.bind(helper);
|
this.removeGraph = helper.removeGraph.bind(helper);
|
||||||
|
|
||||||
@ -75,6 +85,9 @@ export default class GraphApi {
|
|||||||
|
|
||||||
this.addTag = helper.addTag.bind(helper);
|
this.addTag = helper.addTag.bind(helper);
|
||||||
this.removeTag = helper.removeTag.bind(helper);
|
this.removeTag = helper.removeTag.bind(helper);
|
||||||
|
|
||||||
|
// view
|
||||||
|
this.fetch = helper.fetch.bind(helper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
26
pkg/interface/src/subscription/graph.js
Normal file
26
pkg/interface/src/subscription/graph.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import BaseSubscription from './base';
|
||||||
|
|
||||||
|
let getRandomInt = (max) => {
|
||||||
|
return Math.floor(Math.random() * Math.floor(max));
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class GraphSubscription extends BaseSubscription {
|
||||||
|
constructor(store, api, channel) {
|
||||||
|
super(store, api, channel);
|
||||||
|
this.connectionNumber = getRandomInt(999);
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
this.subscribe('/updates/' + this.connectionNumber, 'graph-view');
|
||||||
|
}
|
||||||
|
|
||||||
|
handleEvent(diff) {
|
||||||
|
if ('graph-view' in diff) {
|
||||||
|
this.api.fetch(connectionNumber);
|
||||||
|
} else {
|
||||||
|
// extend
|
||||||
|
this.store.handleEvent(diff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user