Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updating the readme to give an idea what is this lib about.

  • Loading branch information...
commit d5b6361933da0795aa7e012f24ab73a95f985090 1 parent 33ffdc3
@Gozala authored
Showing with 30 additions and 3 deletions.
  1. +30 −3 README.md
View
33 README.md
@@ -1,6 +1,33 @@
-promised-traits
-===============
+# promised-traits #
-Library that mixes goodness of traits and superpowers of promises to allow
+Library that combines goodness of traits and superpowers of promises to allow
writing pretty linear code for doing asynchronous magic.
+ var PromisedTrait = require('promised-traits').PromisedTrait
+ , q = require('q')
+
+ var TExample = PromisedTrait(
+ { firstName: PromisedTrait.required
+ , fullName: function fullName(lastName) {
+ return this.firstName + ' ' + lastName
+ }
+ , greet: function greet(name) {
+ return 'Hello ' + name
+ }
+ })
+
+ var deferred = q.defer()
+ , example = TExample.create(deferred.promise)
+
+ var name = example.fullName('Bar') // returns promise
+ var message = example.greet(name) // returns promise
+
+ // Log message once promise is resolved.
+ q.when(message, function(message) { console.log(message) })
+ // Resolving the promise we used to create our object from.
+ deferred.resolve({ firstName: 'Foo' })
+ // > Hello Foo Bar
+
+# Install #
+
+ npm install promised-traits
Please sign in to comment.
Something went wrong with that request. Please try again.