-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cerebral-module now includes cerebral-provider
- Loading branch information
1 parent
813ac1d
commit 0500bd4
Showing
3 changed files
with
84 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import sequences from "./sequences"; | ||
import oada from "@oada/cerebral-provider"; | ||
import state from "./state" | ||
import oada from "./provider"; | ||
import state from "./state"; | ||
|
||
export default { | ||
state, | ||
|
||
providers: { oada }, | ||
|
||
sequences, | ||
sequences | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Provider } from 'cerebral' | ||
import oada from '@oada/oada-cache'; | ||
import uuid from 'uuid'; | ||
var connections = {}; | ||
|
||
const connect = function connect(args) { | ||
if (!args.connection_id) throw 'connection_id not supplied' | ||
if (args.connection_id && connections[args.connection_id]) return Promise.resolve(connections[args.connection_id]); | ||
return oada.connect(args).then((conn) => { | ||
conn.cache = {}; | ||
connections[args.connection_id] = conn; | ||
return conn; | ||
}) | ||
} | ||
|
||
const get = function get(args) { | ||
if (!args.connection_id) throw 'connection_id not supplied' | ||
if (args.watch && args.watch.signals) { | ||
let sigs = args.watch.signals.map((signal) => { | ||
if (this.context) { | ||
return this.context.controller.hasOwnProperty("getSignal") ? | ||
this.context.controller.getSignal(signal) : | ||
this.context.controller.getSequence(signal); | ||
} | ||
}) | ||
args.watch.func = (payload) => { | ||
sigs.forEach((signal) => { | ||
signal(payload) | ||
}) | ||
} | ||
} | ||
return connections[args.connection_id].get(args); | ||
} | ||
|
||
const put = function put(args) { | ||
if (!args.connection_id) throw 'connection_id not supplied' | ||
return connections[args.connection_id].put(args); | ||
} | ||
|
||
const post = function post(args) { | ||
if (!args.connection_id) throw 'connection_id not supplied' | ||
return connections[args.connection_id].post(args); | ||
} | ||
|
||
|
||
const _delete = function _delete(args) { | ||
if (!args.connection_id) throw 'connection_id not supplied' | ||
return connections[args.connection_id].delete(args); | ||
} | ||
|
||
|
||
const disconnect = function _disconnect(args) { | ||
if (!args.connection_id) throw 'connection_id not supplied' | ||
var connection = connections[args.connection_id]; | ||
connections[args.connection_id] = undefined; | ||
return connection.disconnect(); | ||
} | ||
|
||
const resetCache = function resetCache(args) { | ||
if (!args.connection_id) throw 'connection_id not supplied' | ||
if (!connections[args.connection_id]) return; // reseting a non-existent connection | ||
return connections[args.connection_id].resetCache(args); | ||
} | ||
|
||
export default { | ||
connect, | ||
get, | ||
put, | ||
post, | ||
delete: _delete, | ||
resetCache, | ||
disconnect | ||
}; |