-
Notifications
You must be signed in to change notification settings - Fork 2
redux saga 初步結構 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
horsekitlin
wants to merge
5
commits into
react-native-taiwan:dev
Choose a base branch
from
horsekitlin:master
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,18 +1,3 @@ | ||
| { | ||
| "presets": [ | ||
| "react-native-stage-0/decorator-support" | ||
| ], | ||
| "plugins": [], | ||
| "env": { | ||
| "development": { | ||
| "plugins": [ | ||
| "transform-react-jsx-source" | ||
| ] | ||
| }, | ||
| "production": { | ||
| "plugins": [ | ||
| "transform-remove-console" | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| "presets": [ "es2015","react-native", "stage-0"] | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,30 @@ | ||
| /** | ||
| * Sample React Native App | ||
| * https://github.com/facebook/react-native | ||
| * @flow | ||
| */ | ||
|
|
||
| import React, { Component } from "react"; | ||
| import { Router, Scene } from "react-native-router-flux"; | ||
| import { | ||
| Provider, | ||
| } from 'react-redux'; | ||
| import configureStore from './src/store/configureStore'; | ||
| import Home from "./src/containers/Home"; | ||
| import Counter from "./src/containers/Counter"; | ||
| const store = configureStore(); | ||
|
|
||
| export default class App extends Component { | ||
| render() { | ||
| return ( | ||
| <Provider store={store}> | ||
| <Router> | ||
| <Scene key="root"> | ||
| <Scene path="home" key="home" component={Home} /> | ||
| <Scene path="counter" key="counter" component={Counter} /> | ||
| </Scene> | ||
| </Router> | ||
| </Provider> | ||
| ); | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,101 @@ | ||
| # About React Native Boilerplate | ||
|
|
||
| ## 結構 | ||
|
|
||
| ``` | ||
| ./src | ||
| ├── actions | ||
| │ ├── __tests__ | ||
| │ │ └── demo.test.js | ||
| │ └── demo.js | ||
| ├── components | ||
| │ ├── Counter | ||
| │ │ └── index.js | ||
| │ ├── Home | ||
| │ │ └── index.js | ||
| │ └── __tests__ | ||
| │ ├── Counter.test.js | ||
| │ └── Home.test.js | ||
| ├── constants | ||
| │ └── ActionsType.js | ||
| ├── containers | ||
| │ ├── Counter.js | ||
| │ └── Home.js | ||
| ├── reducers | ||
| │ ├── __tests__ | ||
| │ │ ├── __snapshots__ | ||
| │ │ │ └── demo.test.js.snap | ||
| │ │ └── demo.test.js | ||
| │ ├── demo.js | ||
| │ ├── index.js | ||
| │ └── initialState.js | ||
| ├── sagas | ||
| │ └── index.js | ||
| └── store | ||
| └── configureStore.js | ||
| ``` | ||
|
|
||
| ### actions | ||
|
|
||
| 給 View 發送 action 的管道 | ||
|
|
||
| 固定格式為 | ||
|
|
||
| ```javascript | ||
| export const less = payload => ({ | ||
| type: types.LESS, | ||
| payload | ||
| }); | ||
| ``` | ||
|
|
||
| * payload : 描述此次 action 所需要的資訊包含 saga 發送 request 需要的資訊 | ||
|
|
||
| * type: 描述此次 action 的類型,藉由此讓 reducer 可以分辨執行相對應的 update function | ||
|
|
||
| ### containers | ||
|
|
||
| 描述每一個頁面和相關連的 `action` 和 `reducer` 的描述 | ||
|
|
||
| 利用 `connect` 來將需要的 `action` 和 `reducer` 利用 props 的形式流入 component 提供使用 | ||
|
|
||
| ### components | ||
|
|
||
| 每一個資料夾代表一個頁面 | ||
|
|
||
| 描述顯示在瀏覽器上的 HTML CSS | ||
|
|
||
| 藉由 container 來與 `reducer` 和 `action` 產生關聯 | ||
|
|
||
| 來顯示資料與發送 `action` | ||
|
|
||
| ### reducer | ||
|
|
||
| 提供 `store` 一個可以修改的接口,依據 `action` 的類型去修改相對應的 data | ||
|
|
||
| ### sagas | ||
|
|
||
| 當 `action` 有非同步需求的時候 可以在接收到 `broacast` 之後依據 `action` 的類型去執行後 | ||
|
|
||
| 發送成功或失敗的 `action` 讓 `store` 修改 data | ||
|
|
||
| ## Test | ||
|
|
||
| ``` | ||
| $ npm run test | ||
| ``` | ||
|
|
||
| ### Test Watch | ||
|
|
||
| ``` | ||
| $ npm run test:watch | ||
| ``` | ||
|
|
||
| ## Trouble shotting | ||
|
|
||
| ### missing super() call in constructor | ||
|
|
||
| ``` | ||
| $ vim ./node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js | ||
| ``` | ||
|
|
||
| 在 `XMLHttpRequest` 的 `constructor` 中增加 `super()` | ||
This file contains hidden or 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 @@ | ||
| import "react-native"; | ||
| import React from "react"; | ||
| import App from "../App"; | ||
| import { shallow } from "enzyme"; | ||
|
|
||
| it("renders correctly", () => { | ||
| const tree = shallow(<App />); | ||
| }); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| rootProject.name = 'RNBoilerplate' | ||
| include ':react-native-vector-icons' | ||
| project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android') | ||
|
|
||
| include ':app' |
This file contains hidden or 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,30 @@ | ||
| const { JSDOM } = require('jsdom'); | ||
|
|
||
| const jsdom = new JSDOM(); | ||
| const { window } = jsdom; | ||
|
|
||
| function copyProps(src, target) { | ||
| const props = Object.getOwnPropertyNames(src) | ||
| .filter(prop => typeof target[prop] === 'undefined') | ||
| .map(prop => Object.getOwnPropertyDescriptor(src, prop)); | ||
| Object.defineProperties(target, props); | ||
| } | ||
|
|
||
| global.window = window; | ||
| global.document = window.document; | ||
| global.navigator = { | ||
| userAgent: 'node.js', | ||
| }; | ||
| copyProps(window, global); | ||
|
|
||
| import Enzyme from "enzyme"; | ||
| import Adapter from "enzyme-adapter-react-16"; | ||
|
|
||
| Enzyme.configure({ adapter: new Adapter() }); | ||
|
|
||
| // Ignore React Web errors when using React Native | ||
| console.error = (message) => { | ||
| return message; | ||
| }; | ||
|
|
||
| require('react-native-mock-render/mock'); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,4 @@ | ||
| import { AppRegistry } from 'react-native'; | ||
| import App from './App'; | ||
|
|
||
| AppRegistry.registerComponent('RNBoilerplate', () => App); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
這裡好像打錯了?