Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b9c0c97
Showing
20 changed files
with
3,137 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
{ | ||
"rules": { | ||
"comma-dangle": [2, "never"], | ||
"no-cond-assign": [2, "always"], | ||
"no-console": 2, | ||
"no-constant-condition": 2, | ||
"no-control-regex": 2, | ||
"no-debugger": 2, | ||
"no-dupe-args": 2, | ||
"no-dupe-keys": 2, | ||
"no-duplicate-case": 2, | ||
"no-empty-character-class": 2, | ||
"no-empty": 2, | ||
"no-ex-assign": 2, | ||
"no-extra-boolean-cast": 0, | ||
"no-extra-parens": 2, | ||
"no-extra-semi": 2, | ||
"no-func-assign": 2, | ||
"no-invalid-regexp": 2, | ||
"no-irregular-whitespace": 2, | ||
"no-negated-in-lhs": 2, | ||
"no-obj-calls": 2, | ||
"no-regex-spaces": 2, | ||
"no-sparse-arrays": 2, | ||
"no-unreachable": 2, | ||
"use-isnan": 2, | ||
"valid-typeof": 2, | ||
"no-unexpected-multiline": 2, | ||
|
||
"accessor-pairs": 2, | ||
"block-scoped-var": 2, | ||
"complexity": 0, | ||
"consistent-return": 2, | ||
"curly": 2, | ||
"default-case": 2, | ||
"dot-notation": [2, {"allowKeywords": false}], | ||
"dot-location": [2, "property"], | ||
"eqeqeq": 2, | ||
"guard-for-in": 2, | ||
"no-alert": 2, | ||
"no-caller": 2, | ||
"no-div-regex": 2, | ||
"no-else-return": 2, | ||
"no-empty-label": 2, | ||
"no-eq-null": 2, | ||
"no-eval": 2, | ||
"no-extend-native": 2, | ||
"no-extra-bind": 2, | ||
"no-fallthrough": 2, | ||
"no-floating-decimal": 2, | ||
"no-implicit-coercion": 0, | ||
"no-implied-eval": 2, | ||
"no-invalid-this": 2, | ||
"no-iterator": 2, | ||
"no-labels": 2, | ||
"no-lone-blocks": 2, | ||
"no-loop-func": 2, | ||
"no-multi-spaces": 2, | ||
"no-multi-str": 2, | ||
"no-native-reassign": 2, | ||
"no-new-func": 2, | ||
"no-new-wrappers": 2, | ||
"no-new": 0, | ||
"no-octal-escape": 2, | ||
"no-octal": 2, | ||
"no-param-reassign": 0, | ||
"no-process-env": 2, | ||
"no-proto": 2, | ||
"no-redeclare": [2, { "builtinGlobals": true}], | ||
"no-return-assign": 2, | ||
"no-script-url": 2, | ||
"no-self-compare": 2, | ||
"no-sequences": 2, | ||
"no-throw-literal": 2, | ||
"no-unused-expressions": 2, | ||
"no-useless-call": 2, | ||
"no-useless-concat": 2, | ||
"no-void": 2, | ||
"no-warning-comments": 0, | ||
"no-with": 2, | ||
"radix": 2, | ||
"vars-on-top": 0, | ||
"wrap-iife": [2, "outside"], | ||
"yoda": 0, | ||
|
||
"strict": 2, | ||
|
||
"init-declaration": 0, | ||
"no-catch-shadow": 2, | ||
"no-delete-var": 2, | ||
"no-label-var": 2, | ||
"no-shadow-restricted-names": 2, | ||
"no-shadow": [2, {"builtinGlobals": true, "hoist": "all"}], | ||
"no-undef-init": 2, | ||
"no-undef": 2, | ||
"no-undefined": 2, | ||
"no-unused-vars": [2, {argsIgnorePattern: "^_"}], | ||
"no-use-before-define": 0, | ||
|
||
"callback-return": [2, ["callback", "cb", "next"]], | ||
"global-require": 2, | ||
"handle-callback-err": [2, "^.*(e|E)rr" ], | ||
"no-mixed-requires": [2, true], | ||
"no-new-require": 2, | ||
"no-path-concat": 2, | ||
"no-process-exit": 2, | ||
"no-restricted-modules": [0, "os"], | ||
"no-sync": 2, | ||
|
||
"array-bracket-spacing": [2, "never"], | ||
"block-spacing": 2, | ||
"brace-style": [2, "1tbs", {"allowSingleLine": true }], | ||
"camelcase": 2, | ||
"comma-spacing": 2, | ||
"comma-style": 2, | ||
"computed-property-spacing": 2, | ||
"consistent-this": [2, "self"], | ||
"eol-last": 2, | ||
"func-names": 2, | ||
"func-style": [2, "declaration"], | ||
"id-match": 0, | ||
"indent": [2, 2], | ||
"jsx-quotes": [2], | ||
"key-spacing": [2, {"beforeColon": false, "afterColon": true, mode: "minimum"}], | ||
"lines-around-comment": [2, {"beforeBlockComment": true, "allowBlockStart": true}], | ||
"linebreak-style": [2, "unix"], | ||
"max-nested-callbacks": [2, 2], | ||
"new-cap": 2, | ||
"new-parens": 2, | ||
"newline-after-var": 0, | ||
"no-array-constructor": 2, | ||
"no-continue": 2, | ||
"no-inline-comments": 0, | ||
"no-lonely-if": 2, | ||
"no-mixed-spaces-and-tabs": 2, | ||
"no-multiple-empty-lines": [2, {"max": 2}], | ||
"no-nested-ternary": 0, | ||
"no-new-object": 2, | ||
"no-restricted-syntax": [2, "WithStatement"], | ||
"no-spaced-func": 2, | ||
"no-ternary": 0, | ||
"no-trailing-spaces": 2, | ||
"no-underscore-dangle": 0, | ||
"no-unneeded-ternary": [2, {"defaultAssignment": false}], | ||
"object-curly-spacing": [2, "never"], | ||
"one-var": 0, | ||
"operator-assignment": [2, "always"], | ||
"operator-linebreak": [2, "before"], | ||
"padded-blocks": [2, "never"], | ||
"quote-props": [2, "as-needed"], | ||
"quotes": [2, "single"], | ||
"semi-spacing": 2, | ||
"semi": [2, "always"], | ||
"sort-vars": 0, | ||
"space-after-keywords": 2, | ||
"space-before-keywords": 2, | ||
"space-before-blocks": 2, | ||
"space-before-function-paren": [2, "always"], | ||
"space-in-parens": [2, "never"], | ||
"space-infix-ops": 2, | ||
"space-return-throw-case": 2, | ||
"space-unary-ops": [2, {"words": true, "nonwords": false}], | ||
"spaced-comment": [2, "always", {block: {"exceptions": ["-"]}}], | ||
"wrap-regex": 0, | ||
|
||
"max-depth": 0, | ||
"max-len": [2, 80, 4], | ||
"max-params": 0, | ||
"max-statements": 0, | ||
"no-bitwise": 0, | ||
"no-plusplus": 0 | ||
}, | ||
"env": { | ||
"browser": true, | ||
"node": false, | ||
"commonjs": true, | ||
"worker": false, | ||
"amd": true, | ||
"mocha": false, | ||
"jasmine": false, | ||
"jest": false, | ||
"phantomjs": false, | ||
"protractor": false, | ||
"qunit": false, | ||
"jquery": false, | ||
"prototypejs": false, | ||
"shelljs": false, | ||
"meteor": false, | ||
"mongo": false, | ||
"applescript": false, | ||
"serviceworker": false, | ||
"embertest": false, | ||
"es6": false | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Logs | ||
logs | ||
*.log | ||
|
||
# Temporary Files | ||
temp | ||
.un~ | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Dependency directory | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git | ||
node_modules |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
language: node_js | ||
node_js: | ||
- '0.10' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright (c) 2015, Taylor Everding | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Promissory Arbiter [![Build Status](https://secure.travis-ci.org/taylor1791/promissory-arbiter.png?branch=master)](https://travis-ci.org/taylor1791/promissory-arbiter) [![NPM version](https://badge-me.herokuapp.com/api/npm/promissory-arbiter.png)](http://badges.enytc.com/for/npm/promissory-arbiter) | ||
|
||
> An asynchronous, hierarchical, topic-based, promissory implementation of the pub-sub pattern | ||
## Getting Started | ||
|
||
Getting arbiter up and running is simple. It can be used as a `node_module` on | ||
the client (using WebPack et al.) or on the server. It can even be downloaded | ||
and set into a `third_party` or `vendor` directory and used with a high fidelity | ||
`<script>` tag. Try it out in the console (unless your on github)! | ||
|
||
Here is a quick example to get you started. If you want to see more advanced | ||
examples keep on reading. | ||
|
||
``` | ||
var Arbiter = require('promissory-arbiter'); | ||
var log = function(data, topic) { | ||
console.log(topic, data); | ||
}; | ||
Arbiter.subscribe('work.code', log); | ||
Arbiter.subscribe('work', log); // Subscribes to both `work.code` and `work` | ||
Arbiter.subscribe('', log); // subscribe to all messages | ||
Arbiter.publish('work.code', {type: 'js', duration: 3600}); | ||
``` | ||
|
||
While library will only work in ES3 browsers if you provide an A+ compatible | ||
promise library. If you need one try | ||
[ES6-promise](https://github.com/jakearchibald/es6-promise). | ||
|
||
## Introduction | ||
|
||
Promissory Arbiter is a pure JavaScript implementation of the publish-subscribe | ||
or Observer pattern. "Subscribers" subscribe to topics (or messages or channels) | ||
and the publishers send these messages or publications when they are ready for | ||
them. This allows components to be "loosely" coupled which can lead to more | ||
maintainable code if used correctly. | ||
|
||
Promissory Arbiter is asynchronous by default. This means that all subscribers | ||
are notified asynchronously of messages. This makes code easier to reasonable | ||
because especially when subscribers fire off additional events. This also | ||
lines up with the expectations of most other uses of the callback pattern in | ||
JavaScript effectively reducing cognitive load. Since you have been reading | ||
a while. Take a break by trying the following code in the console if you are | ||
having a hard time understanding what asynchronous means. | ||
|
||
``` | ||
Arbiter.subscribe('my.topic', log); | ||
Arbiter.publish('my.topic', data); | ||
console.log('I execute _before_ the subsriber on the first line!'); | ||
``` | ||
|
||
If you are a synchronous kind of bird, you can set the synchronous option to | ||
true. If you try it in the console, remember that you changed it! For a more | ||
complete list of options checkout [Options](#options). | ||
|
||
``` | ||
Arbiter.options.sync = true; | ||
``` | ||
|
||
When publishing to the topic `"a.b.c"`, all subscribers to `""`, `"a"`, | ||
`"a.b"`, and `"a.b.c"` receive the publication in priority order. If | ||
a subscriber in `"a.b.c"` has a higher priority than a subscriber to `""`, | ||
it will be notified before `""`. The `"."` separates the topic "generations" | ||
and every ancestor of a topic will be notified in addition to original | ||
publisher topic. `""` is an ancestor of every topic (except itself). | ||
Try out the example on the top of the page or read more about topics | ||
in the [Topics](#topic) section below. | ||
|
||
The last unique feature of promissory-arbiter is "promissory" features. When a | ||
publication is made, the publisher gets a promise that it can use to reason | ||
about the subscribers. The promise will resolve according to the specified | ||
options. By default, when all subscribers are complete the promise fulfills | ||
and if any fail, it rejects. This can be change to allow for a number | ||
fulfilled or percent of all subscribers to be fulfilled. You can even relax | ||
the promise to be resolved when a number or percent resolve regardless of | ||
their success or failure status. In addition to this, it has settings for only | ||
running specified number of subscribers at at a time. All of this is documented | ||
in the [Options](#options) section. Or randomly guess the options until you | ||
have something like the following. | ||
|
||
``` | ||
Arbiter.subscribe('get.data', getPeople, {priority: 10}); | ||
Arbiter.subscribe('get.data', getPlaces, {priority: 9}); | ||
Arbiter.subscribe('get.data', getThings, {priority: 8}); | ||
Arbiter.subscribe('get.data', getIdeas, {priority: 7}); | ||
// Let's pretend we are in IE7 and we can only have 2 ajax requests at a time. | ||
Arbiter.publish('get.data', null, {semaphor: 2}).then(function(results) { | ||
// `results` is an array of the people, places, things, and ideas, | ||
// however only 2 of the subscriptions were ever pending at a time! | ||
}, function(errs) { | ||
// If any of the publishers fail, you can have the errors here. | ||
}); | ||
``` | ||
|
||
## License | ||
|
||
The ISC License | ||
|
||
Copyright (c) 2015, Taylor Everding | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"opts": { | ||
"template": "docs/template" | ||
}, | ||
"source": { | ||
"include": "src/" | ||
} | ||
} |
Oops, something went wrong.