Comparing version 0.3.2 to 0.4.0
{ | ||
"name": "syncify", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"description": "", | ||
@@ -17,3 +17,5 @@ "author": "Aldo Bucchi <aldo.bucchi@gmail.com>", | ||
"chai": "~1.5.0", | ||
"coffee-script": "~1.6.3" | ||
"coffee-script": "~1.6.3", | ||
"browserify": "~2.34.0", | ||
"uglify-js": "~2.4.0" | ||
}, | ||
@@ -20,0 +22,0 @@ "repository": "", |
@@ -1,10 +0,56 @@ | ||
# Syncify | ||
# Syncify.js | ||
Pseudo-Blocking Async Javascript Functions | ||
In a nutshell, Syncify allows you to *temporarily bring asynchronous functions into the synchronous world* so you | ||
can focus on solving your problem using clean, imperative code. Here's a quick example of what it looks like: | ||
* Part of the [Radioactive UI Framework](http://github.com/aldonline/radioactive) | ||
* [Reactivity.js](http://github.com/aldonline/reactivity) compatible | ||
```javascript | ||
Installation via NPM | ||
// we have three async functions that go to the server and fetch some data | ||
function getFriendIdsFromServer( id, cb ){ ... } | ||
function getFirstNameFromServer( id, cb ){ ... } | ||
function getLastNameFromServer( id, cb ){ ... } | ||
// we want to create a function that combines them all | ||
function getFriendNamesFromServer( cb ){ ... } | ||
// we don't want to work with callbacks | ||
// so we "syncify" these async functions | ||
// ( we temporarily bring them to the sync world using black magic ) | ||
var getFriendIds = syncify getFriendIdsFromServer | ||
var getFirstName = syncify getFirstNameFromServer | ||
var getLastName = syncify getLastNameFromServer | ||
// and we can now combine them using clean, synchronous imperative code | ||
function getFriendNames( id, cb ){ | ||
var names = []; | ||
var friendIds = getFriendIds( id ); | ||
for ( var i=0; i<friendIds.length; i++ ){ | ||
var id = friendIds[i]; | ||
// look mom. no callbacks! | ||
names.push( getFirstName( id ) + " " + getLastName( id ) ); | ||
} | ||
return names; | ||
} | ||
// now that we have our combined function | ||
// we need to bring it back to the async world | ||
// in order to call it | ||
var getFriendNamesFromServer = syncify.async getFriendNames | ||
// voila! | ||
// we can call our combined function | ||
getFriendNamesFromServer( 78, function( err, names ){ | ||
console.log( names.join( ", " ) ); | ||
}) | ||
``` | ||
## Quickstart | ||
### Get the code | ||
#### Using NPM | ||
```shell | ||
@@ -14,24 +60,10 @@ npm install syncify | ||
Quickstart | ||
#### Load Javascript on the browser | ||
```coffeescript | ||
syncify = require 'syncify' | ||
Take a look at the `/build` folder | ||
# an async function | ||
get_name_async = ( id, cb ) -> ... | ||
# Caveats | ||
# trasnsform to a blocking/sync function | ||
get_name = syncify get_name_async | ||
* Functions must be idempotent | ||
* Their arguments must be JSON serializable | ||
# do something using the sync function | ||
f1 = -> | ||
# notice that we can call toUpperCase on the value | ||
# because this function now returns sychronously | ||
get_name( 8 ).toUpperCase() | ||
# to execute the above function we need to unblock it | ||
f1 = syncify.async f1 | ||
# and the function is async again | ||
f1 (err, res) -> console.log err, res | ||
``` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
100966
2089
69
5
6
3
5
1