├── src ├── index.ts └── handlers │ ├── dom.ts │ ├── init.ts │ ├── history.ts │ └── request.ts ├── circle.yml ├── .gitignore ├── typings.json ├── tsconfig.json ├── LICENSE ├── misc └── handler.ts ├── package.json └── README.md /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from 'boa-core'; 2 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | node: 3 | version: 4.2.2 4 | -------------------------------------------------------------------------------- /src/handlers/dom.ts: -------------------------------------------------------------------------------- 1 | export * from 'boa-handler-dom'; 2 | -------------------------------------------------------------------------------- /src/handlers/init.ts: -------------------------------------------------------------------------------- 1 | export * from 'boa-handler-init'; 2 | -------------------------------------------------------------------------------- /src/handlers/history.ts: -------------------------------------------------------------------------------- 1 | export * from 'boa-handler-history'; 2 | -------------------------------------------------------------------------------- /src/handlers/request.ts: -------------------------------------------------------------------------------- 1 | export * from 'boa-handler-request'; 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | .envrc 3 | .tmp/ 4 | /handlers/ 5 | /index.* 6 | /node_modules/ 7 | /typings/ 8 | -------------------------------------------------------------------------------- /typings.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": {}, 3 | "devDependencies": {}, 4 | "ambientDevDependencies": {}, 5 | "ambientDependencies": {} 6 | } 7 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "module": "commonjs", 5 | "target": "es5", 6 | "noImplicitAny": false, 7 | "noImplicitReturns": true, 8 | "outDir": ".tmp/", 9 | "rootDir": ".", 10 | "sourceMap": false, 11 | "moduleResolution": "node" 12 | }, 13 | "files": [ 14 | "./src/handlers/dom.ts", 15 | "./src/handlers/history.ts", 16 | "./src/handlers/init.ts", 17 | "./src/handlers/request.ts", 18 | "./src/index.ts", 19 | "./typings/main.d.ts", 20 | "./node_modules/typescript/lib/lib.es6.d.ts" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 bouzuya 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /misc/handler.ts: -------------------------------------------------------------------------------- 1 | // handler boilerplate 2 | 3 | import { O, A, Handler } from 'boa-core'; 4 | 5 | const tActionTypeDefault = 'action1'; 6 | const uActionTypeDefault = 'action2'; 7 | 8 | type X = number; 9 | type T = { name: string; params: X; }; // A input 10 | type U = string; // A output 11 | type F = (params: X) => U; 12 | 13 | type XXXOptions = { 14 | fs: { [name: string]: F; }; 15 | tActionType?: string; 16 | uActionType?: string; 17 | }; 18 | 19 | export interface XXXResponse { 20 | handler: Handler; 21 | } 22 | 23 | const init = (options: XXXOptions): XXXResponse => { 24 | const { fs, tActionType, uActionType } = options; 25 | const typeT = tActionType ? tActionType : tActionTypeDefault; 26 | const typeU = uActionType ? uActionType : uActionTypeDefault; 27 | 28 | const dispatch = (action$: O>): O> => { 29 | return action$ 30 | .map(({ data }) => fs[data.name](data.params)) 31 | .map(data => ({ type: typeU, data })); 32 | }; 33 | 34 | const handler = (action$: O>, options: any): O> => { 35 | const is = (action: A): boolean => action.type === typeT; 36 | const other$: O> = action$ 37 | .filter(action => !is(action)); 38 | const target$: O> = action$ 39 | .filter(is); 40 | const result$: O> = dispatch(target$) 41 | .filter(a => !!a) 42 | .share(); 43 | return O.merge(result$, other$); 44 | }; 45 | 46 | return { handler }; 47 | }; 48 | 49 | export { init }; 50 | 51 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "b-o-a", 3 | "description": "A simple framework", 4 | "version": "0.9.0", 5 | "author": { 6 | "name": "bouzuya", 7 | "email": "m@bouzuya.net", 8 | "url": "http://bouzuya.net" 9 | }, 10 | "ava": { 11 | "files": [ 12 | ".tmp/test" 13 | ], 14 | "source": [ 15 | "!**/*.js" 16 | ] 17 | }, 18 | "bugs": { 19 | "url": "https://github.com/bouzuya/b-o-a/issues" 20 | }, 21 | "dependencies": { 22 | "boa-core": "0.8.0", 23 | "boa-handler-dom": "0.7.0", 24 | "boa-handler-history": "0.7.0", 25 | "boa-handler-init": "0.6.0", 26 | "boa-handler-request": "0.5.0" 27 | }, 28 | "devDependencies": { 29 | "ava": "0.14.0", 30 | "parallelshell": "2.0.0", 31 | "rxjs": "5.0.0-beta.6", 32 | "typescript": "1.8.10", 33 | "typings": "0.8.1", 34 | "watch": "0.17.1" 35 | }, 36 | "files": [ 37 | "index.js", 38 | "index.d.ts", 39 | "handlers" 40 | ], 41 | "homepage": "https://github.com/bouzuya/b-o-a#readme", 42 | "keywords": [ 43 | "b-o-a", 44 | "boa" 45 | ], 46 | "license": "MIT", 47 | "main": "./index.js", 48 | "peerDependencies": { 49 | "rxjs": ">=5.0.0-alpha.0 <=5.x" 50 | }, 51 | "repository": { 52 | "type": "git", 53 | "url": "https://github.com/bouzuya/b-o-a" 54 | }, 55 | "scripts": { 56 | "build": "tsc && npm run cp", 57 | "clean": "rm -rf index.* handlers/ .tmp/", 58 | "cp": "parallelshell 'npm run cp1' 'npm run cp2'", 59 | "cp1": "cp -R .tmp/src/index.* ./", 60 | "cp2": "cp -R .tmp/src/handlers/* handlers/", 61 | "md1": "[ -d .tmp/src/handlers ] || mkdir -p .tmp/src/handlers", 62 | "md2": "[ -d handlers ] || mkdir handlers", 63 | "prebuild": "parallelshell 'npm run md1' 'npm run md2'", 64 | "prepublish": "typings install && npm run clean && npm run build", 65 | "test": "ava", 66 | "watch": "parallelshell 'tsc --watch' 'npm run watch-cp' 'ava -- watch", 67 | "watch-cp": "watch --ignoreUnreadable --wait 2 'npm run cp' .tmp/src/" 68 | }, 69 | "typings": "./index.d.ts" 70 | } 71 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ![b-o-a](https://cloud.githubusercontent.com/assets/1221346/13554535/a97537aa-e3ed-11e5-8897-480f0c76c9c5.png) 2 | 3 | b-o-a is a simple framework. 4 | 5 | Twitter hashtag is [#boajs](https://twitter.com/hashtag/boajs). 6 | 7 | ## Concepts 8 | 9 | - uni-directional 10 | - single dispatcher 11 | - action cycle 12 | 13 | ## Types 14 | 15 | - `type O = Observable;` 16 | - `type A = { type: string; data?: T; };` 17 | - `type HandlerOptions = { re: (action: A) => void; };` 18 | - `type Handler = (action$: O>, options?: HandlerOptions) => O>;` 19 | - `type run = (app: Handler) => void`; 20 | 21 | ## Installation 22 | 23 | ``` 24 | $ npm install b-o-a rxjs@5.0.0-beta.6 # you can use rxjs@5.x 25 | ``` 26 | 27 | ## Handlers 28 | 29 | - [bouzuya/boa-handler-dom][] ([npmjs:boa-handler-dom][]) 30 | - [bouzuya/boa-handler-history][] ([npmjs:boa-handler-history][]) 31 | - [bouzuya/boa-handler-init][] ([npmjs:boa-handler-init][]) 32 | - [bouzuya/boa-handler-request][] ([npmjs:boa-handler-request][]) 33 | - [bouzuya/boajs-handler-dom][] ([npmjs:boajs-handler-dom][]) 34 | - [bouzuya/boajs-handler-history][] ([npmjs:boajs-handler-dom][]) 35 | - [bouzuya/boajs-handler-init][] ([npmjs:boajs-handler-init][]) 36 | - [bouzuya/boajs-handler-request][] ([npmjs:boajs-handler-request][]) 37 | 38 | [Search all handlers](https://www.npmjs.com/browse/keyword/boa-handler) 39 | 40 | [bouzuya/boa-handler-dom]: https://github.com/bouzuya/boa-handler-dom 41 | [npmjs:boa-handler-dom]: https://www.npmjs.com/package/boa-handler-dom 42 | [bouzuya/boa-handler-history]: https://github.com/bouzuya/boa-handler-history 43 | [npmjs:boa-handler-history]: https://www.npmjs.com/package/boa-handler-history 44 | [bouzuya/boa-handler-init]: https://github.com/bouzuya/boa-handler-init 45 | [npmjs:boa-handler-init]: https://www.npmjs.com/package/boa-handler-init 46 | [bouzuya/boa-handler-request]: https://github.com/bouzuya/boa-handler-request 47 | [npmjs:boa-handler-request]: https://www.npmjs.com/package/boa-handler-request 48 | [bouzuya/boajs-handler-dom]: https://github.com/bouzuya/boajs-handler-dom 49 | [npmjs:boajs-handler-dom]: https://www.npmjs.com/package/boajs-handler-dom 50 | [bouzuya/boajs-handler-history]: https://github.com/bouzuya/boajs-handler-history 51 | [npmjs:boajs-handler-history]: https://www.npmjs.com/package/boajs-handler-history 52 | [bouzuya/boajs-handler-init]: https://github.com/bouzuya/boajs-handler-init 53 | [npmjs:boajs-handler-init]: https://www.npmjs.com/package/boajs-handler-init 54 | [bouzuya/boajs-handler-request]: https://github.com/bouzuya/boajs-handler-request 55 | [npmjs:boajs-handler-request]: https://www.npmjs.com/package/boajs-handler-request 56 | 57 | ## Libraries 58 | 59 | - [bouzuya/boa-core][] ([npmjs:boa-core][]) 60 | - [bouzuya/boa-router][] ([npmjs:boa-router][]) 61 | - [bouzuya/boa-vdom][] ([npmjs:boa-vdom][]) 62 | - [bouzuya/boajs-core][] ([npmjs:boajs-core][]) 63 | - [bouzuya/boajs-router][] ([npmjs:boajs-router][]) 64 | - [bouzuya/boajs-vdom][] ([npmjs:boajs-vdom][]) 65 | 66 | [bouzuya/boa-core]: https://github.com/bouzuya/boa-core 67 | [npmjs:boa-core]: https://www.npmjs.com/package/boa-core 68 | [bouzuya/boa-router]: https://github.com/bouzuya/boa-router 69 | [npmjs:boa-router]: https://www.npmjs.com/package/boa-router 70 | [bouzuya/boa-vdom]: https://github.com/bouzuya/boa-vdom 71 | [npmjs:boa-vdom]: https://www.npmjs.com/package/boa-vdom 72 | [bouzuya/boajs-core]: https://github.com/bouzuya/boajs-core 73 | [npmjs:boajs-core]: https://www.npmjs.com/package/boajs-core 74 | [bouzuya/boajs-router]: https://github.com/bouzuya/boajs-router 75 | [npmjs:boajs-router]: https://www.npmjs.com/package/boajs-router 76 | [bouzuya/boajs-vdom]: https://github.com/bouzuya/boajs-vdom 77 | [npmjs:boajs-vdom]: https://www.npmjs.com/package/boajs-vdom 78 | 79 | ## Examples 80 | 81 | - [boajs/counter-boa](https://github.com/boajs/counter-boa) ... 0.8.0 / about 200 lines 82 | - [boajs/todomvc-boa](https://github.com/boajs/todomvc-boa) ([demo](http://boajs.github.io/todomvc-boa/)) ... 0.6.2 / about 500 lines 83 | - [boajs/hackernews-boa](https://github.com/boajs/hackernews-boa) ([demo](http://boajs.github.io/hackernews-boa/)) ... core 0.8.0 & dom 0.7.0 & history 0.7.0 / about 1100 lines 84 | 85 | ## Badges 86 | 87 | [![npm version][npm-badge-url]][npm-url] 88 | [![Circle CI][circleci-badge-url]][circleci-url] 89 | 90 | [npm-badge-url]: https://badge.fury.io/js/b-o-a.svg 91 | [npm-url]: https://www.npmjs.com/package/b-o-a 92 | [circleci-badge-url]: https://circleci.com/gh/bouzuya/b-o-a.svg?style=svg 93 | [circleci-url]: https://circleci.com/gh/bouzuya/b-o-a 94 | 95 | ## License 96 | 97 | ### Source Code 98 | 99 | [MIT](LICENSE) ([@bouzuya][user]) 100 | 101 | ### Logo 102 | 103 | MIT ([@hashrock](https://github.com/hashrock)) 104 | 105 | ## Author 106 | 107 | [bouzuya][user] <[m@bouzuya.net][email]> ([http://bouzuya.net][url]) 108 | 109 | [user]: https://github.com/bouzuya 110 | [email]: mailto:m@bouzuya.net 111 | [url]: http://bouzuya.net 112 | --------------------------------------------------------------------------------