The QuickConnect Framework for Node.js
The QuickConnect Framework for Node.js. Flow control, application controller logic, and so much more!
npm install qcnode
The QuickConnect framework for Node.js is designed to help the developer quickly write, debug, and run asynchronous or synchronous code. The framework encourages code re-use and modularity.
There are many ways!
QuickConnect = require'qcnode'QuickConnectvar qc =qccommand'list filtered files'thisvalcfifqc === this //it doesreturn thisSTACK_CONTINUEelsereturn "this is impossible"thisdcffsreaddirdatadirPathiferr//maybe handle it here, if I wantqcasyncStackErrorerrreturnqcasyncStackContinue'files'filesreturn qcWAIT_FOR_DATAthisdcfdatafilteredFiles = datafilesfilterreturn val != datafilterthisvcfforvar fi in datafilteredFilesconsole.logfireturn qcSTACK_EXITvar stack = qchandleRequest'login' myData // .handleRequest === .runstackon'error'//handle the error out here, where I know what is going on.console.log"unable to filter files right now: "+errstackstackon'end'console.log'yay!'
qcisolate'request'thisisolate 'GET'thiscommand'contest'thisvalcfif+ < limitreturn "the contest has not begun"return thisSTACK_CONTINUEthisdcfdataresponsewriteHead200dataresponseendJSONstringifymessage:"you are a winner!"return thisSTACK_CONTINUEthisisolate 'DELETE'//more logichttpcreateServer//this will dynamically select what command to run based on the url!url = require'url'parserequrl trueaction = 'request'reqmethodurlParts = urlpathnamesplit'/'filterreturn v//removes ''action = actionconcaturlPartstryqcrunactionresponse:resreswrite500resend"error"reswrite422resendJSONstringifyerrors:failsMsgscatch err//stack is not definedreswrite404resendcached404page
Um… No I didn't! Pay no attention to the man behind the callbacks! This code gets run top-to-bottom; the callbacks are just helpers.
Well, fine. These examples are actually written in a shorthand that was helpful while writting coffeescript. it looks like this in coffeescript:
qcisolate 'request'->@isolate 'GET'->@command 'contest'->@valcfif + < limit"the contest has not begun"else@STACK_CONTINUE@dcfdataresponsewriteHead 200dataresponseend JSONstringify message:"you are a winner!"@isolate 'DELETE'->#more logic
It's pretty simple to write and read with that shorthand. Here is what is actually happening in the code:
var delim = qcmapperisolateDelimiterqcmappermapCommandToValCF'request''GET''contest'joindelim myValCFqcmappermapCommandToValCF'request''GET''contest'joindelim myDCF//ect...
That is also very readable, but it takes a lot of characters.
command, and the
cf functions all return the same object that is
this in the callbacks, you can chain! Here is an example from the qc tests:
basiccommand'basic stack to call'valcfif datahelolreturn qcSTACK_CONTINUEelsereturn "this should not have been returned"dcfassertdatahelolreturn thisSTACK_CONTINUEdcfsetTimeoutqcasyncStackContinue5return thisWAIT_FOR_DATAdcfsetTimeoutqcasyncStackContinue'key''koy'50return thisWAIT_FOR_DATAdcfassertequaldatakey'koy'return thisSTACK_CONTINUEvcfdatadone = truereturn thisSTACK_CONTINUE
You just have to remember that
cf functions do not return the same object. This is not valid:
Remember, if you can chain something, you can store it.
iso = basicisolateisolcomOne = isocommandmycomcomOnevalcfmyfuncdcfdfunccomTwo = isocommandotherComcomTwoect
No, but you can with mixins!
So this is awesome! You can use QC in the way that works for you. It's more than just flow control, it's designed to help you get things done faster, higher, and stronger.
Head on over to our example page!
QuickConnect started as a response to some of the problems encountered writing code for Enterprise Java servers. The framework pattern evolved for several years in a hybrid mobile environment (QCHybrid, iOS and Android) which provided tools for rapid prototyping of cross-platform apps.
QC is pretty mature and very functional, so it didn't make sense to publish a version <1.0.0
Here is how it works: When we change to version x.y.z
- x : your stuff will probably break
- y : your stuff will probably not break
- z : we fixed something, wrote a test, or something small
Because QC has a history older than Node.js, it has some things in it that are leftovers from other incarnations. 'handleRequest' is the oldest part; it comes from living on a server that handles client requests. It has been pointed out that a 'request', a 'command', and a 'stack' are all related, but come from different points in the history. We want to increase the 'y' part of the version by building better ways for people to use QC in their codeflow and workflow.
Fork the repo, submit a pull request and tell us your rational for the change; we would love to hear all ideas.
We feel the core logic of QC is pretty set in version 1.0.0, but if you have ideas for version 2.0.0, fork the repo or drop us a line!
Copyright (c) 2013 Joshua Barney, Lee Barney
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.