Created
November 24, 2015 22:32
-
-
Save cdaringe/ef6239b27c629e5cf9ff to your computer and use it in GitHub Desktop.
coinstac-api-via-websockets
This file contains hidden or 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
/** | |
* server API is imported into main thread as a lib | |
* coinstac render process or test processes can import the API, which | |
* exports server behaviors, and client functions to call | |
*/ | |
// in main thread | |
var copperwad = require('copperwad'); // because we don't believe in boring names | |
copperwad.listen('1492'); | |
copperwad.on('analysis:add', copperwad.server.analysis.add); | |
copperwad.on('consortium:join', copperwad.server.consortium.join); | |
// in render thread, component | |
... | |
handleClickAddAnalysis: function() { | |
var analysis = { | |
// would really extract from forms | |
name: 'cranial-disfigurement-std-measures', | |
git: 'http://github.com/bilbo/cranial-assess' | |
}; | |
requestAddAnalysis(analysis); // dispatch action | |
} | |
// in render thread, async actions | |
var copperwad = require('copperwad'); | |
function requestAddAnalysis(analysis) { | |
dispatch({ | |
type: 'REQUEST_ADD_ANALYSIS', | |
... | |
}) | |
copperwad.client.analysis.add(analysis); | |
} | |
copperwad.client.on('analysis:added', function(rslt) { | |
dispatch({ | |
type: 'RESOLVE_ADD_ANALYSIS', | |
... | |
}) | |
if (rslt.error) { | |
return app.notify(...) | |
} | |
app.notify(`cranial-...-measures analysis added to consortium xyz`); | |
addAnalysis(analysis); // add analysis to state for rendering | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment