Skip to content

Commit

Permalink
update to dryadic 0.2.0 - moved Store back into supercollider.js
Browse files Browse the repository at this point in the history
  • Loading branch information
crucialfelix committed Apr 27, 2016
1 parent 8e051c0 commit 7048f31
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"bluebird": "^3.3.5",
"chalk": "^1.1.3",
"commander": "^2.9.0",
"dryadic": "^0.1.0",
"immutable": "^3.8.0",
"dryadic": "^0.2.0",
"immutable": "^3.8.1",
"js-yaml": "^3.6.0",
"ncp": "^2.0.0",
"node-uuid": "^1.4.7",
Expand Down
2 changes: 1 addition & 1 deletion src/dryadic/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import _ from 'underscore';
import {bootServer, bootLang} from '../server/internals/side-effects';
import {Promise} from 'bluebird';
import {Store} from 'dryadic';
import Store from '../server/internals/Store';


Promise.onPossiblyUnhandledRejection((error) => {
Expand Down
2 changes: 1 addition & 1 deletion src/server/ServerState.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import Immutable from 'immutable';
import {Store} from 'dryadic';
import Store from './internals/Store';
import * as alloc from './internals/allocators';
import {watchNodeNotifications} from './node-watcher';

Expand Down
1 change: 1 addition & 0 deletions src/server/__tests__/ServerState-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ jest.dontMock('../server');
jest.dontMock('../ServerState');
jest.dontMock('../internals/allocators');
jest.dontMock('../internals/SendOSC');
jest.dontMock('../internals/Store');
jest.dontMock('rx');

var Server = require('../server').Server;
Expand Down
1 change: 1 addition & 0 deletions src/server/__tests__/node-watcher-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ jest.dontMock('rx');
jest.dontMock('../node-watcher');
jest.dontMock('../server');
jest.dontMock('../ServerState');
jest.dontMock('../internals/Store');
jest.dontMock('../internals/SendOSC');

var nw = require('../node-watcher');
Expand Down
43 changes: 43 additions & 0 deletions src/server/internals/Store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

import Immutable from 'immutable';

/**
* A store that holds the state tree.
*
* Holds an Immutable.Map and offers functions to mutate sub-states in that tree,
* and stores the new state.
*
*/
export default class Store {

constructor() {
this.state = Immutable.Map();
}

getIn(keys, notSetValue) {
return this.state.getIn(keys, notSetValue);
}

/**
* Fetch the object at keys
* pass it to the function which mutates it and returns new sub state.
*/
mutateState(keys, fn) {
this.state = this.state.updateIn(keys, Immutable.Map(), fn);
}

/**
* Fetch one part of the state,
* mutate it with the callback,
* which returns result, subState.
* Save the subState back into state and return the result.
*
* @returns {any} result
*/
mutateStateAndReturn(keys, fn) {
var result, subState;
[result, subState] = fn(this.state.getIn(keys, Immutable.Map()));
this.state = this.state.setIn(keys, subState);
return result;
}
}
2 changes: 1 addition & 1 deletion src/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ export class Server extends EventEmitter {
* Boot a server with options and connect
*
* @param {Object} options - command line options for server
* @param {Store} store - optional Dryadic Store to hold Server state
* @param {Store} store - optional external Store to hold Server state
* @returns {Promise} - resolves with the Server
*/
export function boot(options={}, store=null) {
Expand Down

0 comments on commit 7048f31

Please sign in to comment.