-
Notifications
You must be signed in to change notification settings - Fork 3
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 16a1551
Showing
35 changed files
with
6,202 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,44 @@ | ||
{ | ||
"presets": [ | ||
["env", { "modules": false }], | ||
"flow" | ||
], | ||
"plugins": [ | ||
"transform-class-properties", | ||
"transform-object-rest-spread" | ||
], | ||
"env": { | ||
"test": { | ||
"plugins": [ | ||
"transform-es2015-modules-commonjs", | ||
"transform-object-rest-spread", | ||
"transform-class-properties", | ||
"babel-jest-assertions" | ||
] | ||
}, | ||
"production": { | ||
"plugins": [ | ||
"transform-es2015-modules-commonjs", | ||
"transform-object-rest-spread", | ||
"transform-class-properties" | ||
] | ||
}, | ||
"lib": { | ||
"presets": [ | ||
"env", | ||
"flow" | ||
], | ||
"plugins": [ | ||
"transform-es2015-modules-commonjs", | ||
"transform-object-rest-spread", | ||
"transform-class-properties" | ||
] | ||
}, | ||
"es": { | ||
"plugins": [ | ||
"transform-object-rest-spread", | ||
"transform-class-properties" | ||
] | ||
} | ||
} | ||
} |
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,20 @@ | ||
version: 2 | ||
jobs: | ||
build: | ||
docker: | ||
- image: circleci/node:8.4.0 | ||
|
||
working_directory: ~/repo | ||
|
||
steps: | ||
- checkout | ||
- restore_cache: | ||
keys: | ||
- yarn-{{ arch }}-{{ .Branch }}-{{ checksum "package.json" }} | ||
- run: yarn install | ||
- save_cache: | ||
paths: | ||
- node_modules | ||
key: yarn-{{ arch }}-{{ .Branch }}-{{ checksum "package.json" }} | ||
- run: yarn run coverage | ||
- run: cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js |
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 @@ | ||
webpack.config.js |
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,43 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"env": { | ||
"browser": true, | ||
"node": true, | ||
"es6": true, | ||
"jest/globals": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:flowtype/recommended" | ||
], | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"experimentalObjectRestSpread": true, | ||
"jsx": true | ||
}, | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"jest", | ||
"flowtype", | ||
], | ||
"rules": { | ||
"indent": [2, 2, {"SwitchCase": 1}], | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"max-len": [2, 90, 4, {"ignoreUrls": true}], | ||
"quotes": [ | ||
"error", | ||
"single" | ||
], | ||
"semi": [ | ||
"error", | ||
"never" | ||
], | ||
"no-console": 0, | ||
}, | ||
"settings": { | ||
} | ||
} |
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,11 @@ | ||
[ignore] | ||
.*/node_modules/.*enzyme*./*. | ||
|
||
[include] | ||
|
||
[libs] | ||
|
||
[lints] | ||
|
||
[options] | ||
suppress_comment= \\(.\\|\n\\)*\\flow-ignore |
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,54 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
build | ||
lib | ||
dist | ||
es | ||
|
||
# Dependency directories | ||
node_modules/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
.DS_Store |
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,7 @@ | ||
# asset directories | ||
docs | ||
doc | ||
website | ||
images | ||
assets | ||
!istanbul-reports/lib/html/assets |
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,114 @@ | ||
<h1 align="center">Rxact</h1> | ||
|
||
[![npm version](https://img.shields.io/npm/v/rxact.svg?style=flat-square)](https://www.npmjs.com/package/rxact) | ||
[![CircleCI master](https://img.shields.io/circleci/project/github/Darmody/rxact/master.svg?style=flat-square)](https://circleci.com/gh/Darmody/rxact/tree/master) | ||
[![Coveralls master](https://img.shields.io/coveralls/github/Darmody/rxact/master.svg?style=flat-square)](https://coveralls.io/github/Darmody/rxact) | ||
|
||
Rxact 是一个基于 `Observable` 实现的 `Javascript app` 应用管理库。 | ||
|
||
## 介绍 | ||
Rxact 致力于帮助应用管理数据与业务逻辑,与 Redux 等 state 容器不同的是,Rxact 在管理 state 之外,还会帮助开发者很好地封装应用逻辑。需要注意的是,使用 Rxact 将会涉及 **reactive programing** 的概念,请确保这是你熟悉或希望使用的特性。 | ||
|
||
## 核心概念 | ||
|
||
### 没有 Store | ||
|
||
在 Rxact 中没有 Store 的概念,但是依然可以存储数据。在类似于 Redux 的 state 容器中都会有 Store 的概念,这是因为他们的设计理念本身就是对 state 进行管理。但是对于现在越来越复杂的 Javascript 应用来说,只有 state 管理是不够的,还需要很好的业务逻辑管理。因此 Rxact 以流的概念来管理 state 和业务逻辑。 | ||
|
||
### 流 | ||
|
||
现在开始自顶向下地构想你的应用逻辑,从用户登录开始直到某个按钮的点击行为,是不是可以看到一条条完整的**逻辑流**,不同的逻辑流之间还有可能互相融合或者分流到其他流中。这就是 Rxact 希望做到的,通过**流**来管理你的应用。 | ||
|
||
### StateStream | ||
|
||
`Rxact` 中最核心的组件就是 **StateStream**,StateStream 就是一个数据流。在这个数据流中你可以定义你的数据如何变化,你有哪些针对这些数据的事件流或操作。甚至还可以把不同的 StateStream 组合起来形成一个新的 StateStream。这就是 `Rxact` 组织和管理应用的方式。 | ||
|
||
## 安装 | ||
|
||
``` | ||
yarn add rxact | ||
``` | ||
|
||
## 起步 | ||
|
||
第一步, 选择你喜欢的 Observable 库。 | ||
|
||
`Rxact` 支持任何基于[ECMAScript Observable 标准](https://github.com/tc39/proposal-observable) 的实现。 | ||
目前可以配合使用的库包括(但不仅限于): | ||
* [RxJS 5](https://github.com/ReactiveX/rxjs) | ||
* [zen-observable](https://github.com/zenparsing/zen-observable) | ||
* [xstream](https://github.com/staltz/xstream) (配合使用:[rxact-xstream](https://github.com/Darmody/rxact-xstream)) | ||
* 更多... | ||
|
||
第二步,配置 `Rxact`。 | ||
|
||
假设你选择了 `RxJS` 作为 `Observable` 实现,现在你需要配置 `Rxact`: | ||
|
||
```javascript | ||
import { StateStream } from 'rxact' | ||
import Rx from 'rxjs' | ||
import { setup } from 'rxact' | ||
|
||
setup({ Observable: Rx.Observable }) | ||
``` | ||
|
||
第三步,我们以计数器为例写一个简单的样例 | ||
|
||
```javascript | ||
import { StateStream } from 'rxact' | ||
|
||
/** | ||
* StateStream 是一个管理 state 的流。 | ||
* 你需要为流起一个名字,并赋予一个初始值。有了这个流后,就可以往流里更新新的数据, | ||
* 并监听流的变化,做出相应的动作 | ||
*/ | ||
const stream = new StateStream('stream', 0) | ||
|
||
/** | ||
* emitter 用于定义数据的更新操作,这里定义了一个名为 increment 的操作, | ||
* 每次执行这个操作,"stream"流将会得到之前数据加上输入值的新值。 | ||
*/ | ||
stream.emitter('increment', value => prevState => (prevState + value)) | ||
|
||
/** | ||
* 通过订阅 stream 获取最新的值并打印出来。 | ||
* 在 subscribe 时就会立刻输出当前值,在这里就是初始值 0 | ||
**/ | ||
stream.subscribe(value => { console.log(value) }) | ||
|
||
stream.increment(1) | ||
// subscribe 将会输出 1 | ||
stream.increment(1) | ||
// subscribe 将会输出 2 | ||
stream.increment(2) | ||
// subscribe 将会输出 4 | ||
``` | ||
|
||
更多信息请查看详细文档。 | ||
|
||
## 示例 | ||
|
||
下面是更复杂,更多功能的示例 | ||
|
||
* [计数器](https://darmody.github.io/rxact-examples/counter) | ||
* [TodoMVC](https://darmody.github.io/rxact-examples/todomvc) | ||
* [异步事件案例](https://darmody.github.io/rxact-examples/async) | ||
* [贴近现实的复杂案例](https://darmody.github.io/rxact-examples/real-world) | ||
|
||
你可以在 [rxact-examples](https://github.com/darmody/rxact-examples) 看到上述例子的源代码。 | ||
|
||
## 插件 | ||
|
||
`Rxact` 可以配置插件来增强功能。常用的插件有: | ||
* [Rxact-React](https://github.com/Darmody/rxact-react) `Rxact` 对 `React` 的支持。 | ||
* [Rxact-Debugger](https://github.com/Darmody/rxact-debugger) `Rxact` 调试插件,可以在浏览器控制台下调用 `StateStream`, 并有友好的日志帮助调试。 | ||
* [Rxact-Rxjs](https://github.com/Darmody/rxact-rxjs) `Rxact` 天然支持 `Rxjs`, 这个组件提供了更高级的功能支持。 | ||
* [Rxact-Xstream](https://github.com/Darmody/rxact-xstream) `Rxact` 对 `xstream` 的支持。 | ||
|
||
## 文档 | ||
|
||
敬请期待... | ||
|
||
## 协议 | ||
|
||
[MIT](https://github.com/darmody/rxact/blob/master/LICENSE) |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017-present, Huanyu (Darmody) Cai | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Oops, something went wrong.