Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b9b6c0c

Browse files
author
kenberkeley
committed
add js/html syntax highlight
1 parent ce679fd commit b9b6c0c

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

‎middleware-onion-model.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
## § Express 的中间件
88

9-
```
9+
```js
1010
/** app.js **/
1111
var express = require('express')
1212
var app = express()
@@ -81,7 +81,7 @@ B middleware1 结束
8181

8282
## § Redux 的中间件[(在线演示)](http://jsbin.com/pazica/edit?html,console)
8383

84-
```
84+
```html
8585
<!DOCTYPE html>
8686
<html>
8787
<head>

‎redux-advanced-tutorial.md‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
2727
### ⊙ 源码分析
2828

29-
```
29+
```js
3030
/**
3131
* 看起来逼格很高,实际运用其实是这样子的:
3232
* compose(f, g, h)(...arg) => f(g(h(...args)))
@@ -54,7 +54,7 @@ export default function compose(...funcs) {
5454

5555
这里的关键点在于,`reduceRight` 可传入初始值。由于 `reduce / reduceRight` 仅仅是方向的不同,因此下面用 `reduce` 说明即可:
5656

57-
```
57+
```js
5858
var arr = [1, 2, 3, 4, 5]
5959

6060
var re1 = arr.reduce(function(total, i) {
@@ -71,7 +71,7 @@ console.log(re2) // 115
7171
## &sect; Redux API · [createStore(reducer, [initialState])][createStore]
7272
### ⊙ 源码分析
7373

74-
```
74+
```js
7575
import isPlainObject from 'lodash/isPlainObject'
7676
import $$observable from 'symbol-observable'
7777

@@ -332,7 +332,7 @@ reducers/
332332
├── todosReducer.js
333333
```
334334

335-
```
335+
```js
336336
/** 本代码块记为 code-9 **/
337337
/* reducers/index.js */
338338
import { combineReducers } from 'redux'
@@ -410,7 +410,7 @@ reducers/
410410
├── todoListReducer.js
411411
```
412412

413-
```
413+
```js
414414
/* reducers/index.js */
415415
import { combineReducers } from 'redux'
416416
import counterReducer from './counterReducer'
@@ -478,7 +478,7 @@ rootReducer(state, action) —→∑ ↗ optTimeReducer(optTime, action) ---
478478
### ⊙ 源码分析
479479
> 仅截取关键部分,毕竟有很大一部分都是类型检测警告
480480
481-
```
481+
```js
482482
function combineReducers(reducers) {
483483
var reducerKeys = Object.keys(reducers)
484484
var finalReducers = {}
@@ -518,7 +518,7 @@ function combineReducers(reducers) {
518518
519519
### ⊙ 源码分析
520520

521-
```
521+
```js
522522
/* 为 Action Creator 加装上自动 dispatch 技能 */
523523
function bindActionCreator(actionCreator, dispatch) {
524524
return (...args) => dispatch(actionCreator(...args))
@@ -591,7 +591,7 @@ $('#btn').on('click', function() {
591591
诸如统一的日志记录、引入 thunk 统一处理异步 Action Creator 等都属于中间件
592592
下面是一个简单的打印动作前后 `state` 的中间件:
593593

594-
```
594+
```js
595595
/* 装逼写法 */
596596
const printStateMiddleware = ({ getState }) => next => action => {
597597
console.log('state before dispatch', getState())
@@ -625,7 +625,7 @@ function printStateMiddleware(middlewareAPI) { // 记为【锚点-1】,中间
625625
说白了,Store 增强器就是对生成的 `store` API 进行改造,这是它与中间件最大的区别(中间件不修改 `store` 的 API)
626626
而改造 `store` 的 API 就要从它的缔造者 `createStore` 入手。例如,Redux 的 API `applyMiddleware` 就是一个 Store 增强器:
627627

628-
```
628+
```js
629629
import compose from './compose' // 这货的作用其实就是 compose(f, g, h)(action) => f(g(h(action)))
630630

631631
/* 传入一坨中间件 */
@@ -668,7 +668,7 @@ export default function applyMiddleware(...middlewares) {
668668
最终返回的虽然还是 `store` 的那四个 API,但其中的 `dispatch` 函数的功能被增强了,这就是所谓的 Store Enhancer
669669

670670
### ⊙ 综合应用 ( [在线演示][jsbin] )
671-
```
671+
```html
672672
<!DOCTYPE html>
673673
<html>
674674
<head>
@@ -723,7 +723,7 @@ store.dispatch(dec());
723723

724724
实际上,上面生成 `store` 的代码还可以更加优雅:
725725

726-
```
726+
```js
727727
/** 本代码块记为 code-10 **/
728728
var store = Redux.createStore(
729729
reducer,
@@ -735,7 +735,7 @@ var store = Redux.createStore(
735735

736736
> 重温一下 `createStore` 完整的函数签名:`function createStore(reducer, preloadedState, enhancer)`
737737
738-
```
738+
```js
739739
/** 本代码块记为 code-11 **/
740740
import { createStore, applyMiddleware, compose } from 'redux'
741741

@@ -757,7 +757,7 @@ const store = createStore(
757757

758758
`createStore` 的源码分析的开头部分,我省略了一些代码,现在奉上关键部分:
759759

760-
```
760+
```js
761761
/** 本代码块记为 code-12 **/
762762
if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') {
763763
// 这里就是上面 code-10 的情况,只传入 reducer 和 Store Enhancer 这两个参数

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /