1 | ![BothIO Logo](http://docs.michaelzoidl.com/GithubLogoPaths.svg)
|
2 |
|
3 | ![](https://img.shields.io/badge/unicorn-approved-blue.svg)
|
4 | [![Gratipay](http://img.shields.io/gratipay/michaelzoidl.svg)](https://gratipay.com/michaelzoidl/)
|
5 | [![Build Status](https://travis-ci.org/michaelzoidl/both.io.svg?branch=master)](https://travis-ci.org/michaelzoidl/both.io)
|
6 | [![bitHound Score](https://www.bithound.io/github/michaelzoidl/both.io/badges/score.svg)](https://www.bithound.io/github/michaelzoidl/both.io)
|
7 | [![Codacy Badge](https://img.shields.io/codacy/98f77bcc84964e67a2754e563b962d27.svg)](https://www.codacy.com/app/me_1438/both-io)
|
8 | [![devDependency Status](https://david-dm.org/michaelzoidl/both.io/dev-status.svg)](https://david-dm.org/michaelzoidl/both.io#info=devDependencies)
|
9 |
|
10 | ## What is BothIO?
|
11 | Simply, it's a library based on the [CQS-Princip](http://en.wikipedia.org/wiki/Command%E2%80%93query_separation), where your methods are separated by **commands** and **queries**.<br><br>
|
12 | What BothIO makes so special is the NodeJS/Client-Support, so you can execute your commands and queries from your node-side as well as from your client-side.
|
13 |
|
14 | ## Example
|
15 | ```javascript
|
16 |
|
17 | var myToDoList = [];
|
18 |
|
19 | // # Define a Command
|
20 | // Server:
|
21 | both.command('CreateTodo', function(name, payload, callback){
|
22 | myToDoList.push(payload.todoName);
|
23 | });
|
24 |
|
25 | // Execute a Command
|
26 | // Client:
|
27 | both('CreateTodo', {
|
28 | todoName: 'eat some chocolate'
|
29 | });
|
30 |
|
31 |
|
32 | // Listen to a defined Command
|
33 | // Server:
|
34 | both.on('CreateTodo', function(name, payload){
|
35 | console.log('Todo Created:', payload.todoName);
|
36 | });
|
37 |
|
38 | // Listen to all Commands
|
39 | // Client:
|
40 | both.on(function(commandName, payload){
|
41 | console.log('The command', commandName, 'was executed!');
|
42 | console.log('with the payload:', payload);
|
43 | });
|
44 |
|
45 |
|
46 | // # Add a Callback
|
47 | // Server:
|
48 | both.query('GetAllTodos', function(name, payload, callback){
|
49 | someDatabase.query('getAllTodos', function(todos){
|
50 | callback(todos);
|
51 | });
|
52 | });
|
53 |
|
54 | // Client:
|
55 | both('GetAllTodos', {}, function(todos){
|
56 | // Use Todos at the client
|
57 | })
|
58 |
|
59 | ```
|
60 | [And there's something more planed](https://github.com/michaelzoidl/both.io/blob/master/PLANED.md)
|
61 |
|
62 | ## Battle-Tested
|
63 | This project is used at the [entertain.io](https://github.com/michaelzoidl/entertain.io) platform.
|
64 |
|
65 |
|
66 | ## Contribute
|
67 | BothIO uses the new ES6 standard and is tested with mocha, plus we package the code with webpack.
|
68 | <br><br>
|
69 | __You want contribute? Here is how you start:__<br>
|
70 | _Clone repo_<br>
|
71 | `git clone git@github.com:michaelzoidl/both.io.git`<br>
|
72 | _Run the unit-tests_<br>
|
73 | `npm run test`<br>
|
74 | _Pack the code and save it in the dist-folder_<br>
|
75 | `npm run pack`<br>
|
76 | _Develop, it starts a mocha-watcher_<br>
|
77 | `npm run develop`
|