0.0.2 • Published 9 years ago
vnls-promise v0.0.2
vnls-promise
Cross platform Promise.
Install:
Nodejs:
On node nodejs
npm install vnls
npm install vnls-event
npm install vnls-promise
Then, somewhere at the top of your code
require('vnls');
require('vnls-event');
require('vnls-promise');
There is no need to bind it to a var because var VNLS is made global to the nodejs process so it's behavior is exactly like in a browser environment. All-though this IS a kind of pollution on nodejs.
Browser
In a browser (you may also download the file first):
<script type="text/javascript" src="https://raw.githubusercontent.com/jorritd/vnls/master/lib/vnls.min.js"></script>
<script type="text/javascript" src="https://raw.githubusercontent.com/jorritd/vnls-event/master/lib/vnls-event.min.js"></script>
<script type="text/javascript" src="https://raw.githubusercontent.com/jorritd/vnls-promise/master/lib/vnls-promise.min.js"></script>
Usage:
var promise = VNLS.getObject('event',"Promise");
promise.Do('set a timeOut and 2 increments',
// Can we pass something
// extra to 'this' promise
function(promise){
callback_counter ++;
setTimeout(function(){
// promise.done();
setTimeout(function(){
promise.done();
},100);
},100);
},
function(promise){
callback_counter ++;
promise.done();
},
function(promise){
callback_counter ++;
promise.done();
}
).whenDone( function(){
success_called = true;
}).whenFail( function(){
error_called = true;
});
or:
promise.Do(
function(promise){
callback_counter ++;
promise.done();
},
function(promise){
callback_counter ++;
// This block is causing an error
// So the next block will be valid
promise.fail();
},
function(promise){
callback_counter ++;
promise.done();
}
).orDo(
function(promise){
callback_counter ++;
promise.done();
},
function(promise){
callback_counter ++;
promise.done();
},
function(promise){
callback_counter ++;
promise.done();
}
).whenDone( function(){
success_called = true;
}).whenFail( function(){
error_called = true;
});
or:
promise.Do(
function(promise){
promise.done();
}
).thenDo(
function(promise){
// console.log('Then called');
setTimeout(function(){
// console.log('READY');
// self.pOptions.current_level == 2 at this position
// console.log(u.inspect(promise),true);
promise.done();
},100);
}
).orDo(
function(promise){
// console.log('Or called');
// console.log('ERROR');
// console.log(u.inspect(promise),true);
promise.fail();
}
).whenDone( function(){
success_called = true;
}).whenFail( function(){
error_called = true;
});
Dependencies:
Development:
- jasmine-node Testing
npm install jasmine-node
- nodewatch Autotesting TDD
npm install nodewatch
- uglify-js Building
npm install uglify-js
- jake rake, make, ant substitute (Java-script all the way)
npm install -g jake
For jake these are the commands:
jake compress
: build minified version in './lib/*'jake test
: run the specsjake autotest
: run the specs on a filechange for TDD
For testing in a browser environment just point your browser to 'specs/index.html'.
It should run the same specs as jake test
does. (The tests cover both browser and server)
0.0.2
9 years ago