-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Redux Support #93
Merged
Merged
Redux Support #93
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1361043
wepy-global
dolymood 8bfd037
wepy-redux
dolymood 8fa8745
fn context
dolymood 22a9e20
del global
dolymood 80eb965
dir end add /
dolymood 912b760
nam add lodash/freeglobal hack & fix babel-plugin-transform-decorator…
dolymood d810c45
add $
dolymood dc818fc
readme
dolymood 0961e92
redux 配置
dolymood 1d3e792
redux template
dolymood 7a6e841
clear code
dolymood f326c7a
concat replace push.apply
dolymood 0fe8495
add comment
dolymood eedab8a
add comment
dolymood 5330f7a
for windows & linux files
dolymood 5f43884
for windows & linux files
dolymood 4d4b8fd
remove path.sep
Gcaufy b74ad74
added slash
Gcaufy d3fa989
added ci generator test case
Gcaufy 5796e4c
pages add redux
dolymood 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 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 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 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 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 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,73 @@ | ||
<style lang="less"> | ||
.container { | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: space-between; | ||
box-sizing: border-box; | ||
} | ||
</style> | ||
|
||
<script> | ||
import wepy from 'wepy' | ||
import 'wepy-async-function' | ||
import { setStore } from 'wepy-redux' | ||
import configStore from './store' | ||
|
||
const store = configStore() | ||
setStore(store) | ||
|
||
export default class extends wepy.app { | ||
config = { | ||
pages: [ | ||
'pages/index' | ||
], | ||
window: { | ||
backgroundTextStyle: 'light', | ||
navigationBarBackgroundColor: '#fff', | ||
navigationBarTitleText: 'WeChat', | ||
navigationBarTextStyle: 'black' | ||
} | ||
} | ||
|
||
globalData = { | ||
userInfo: null | ||
} | ||
|
||
constructor () { | ||
super() | ||
this.use('requestfix') | ||
} | ||
|
||
onLaunch() { | ||
this.testAsync() | ||
} | ||
|
||
sleep (s) { | ||
return new Promise((resolve, reject) => { | ||
setTimeout(() => { | ||
resolve('promise resolved') | ||
}, s * 1000) | ||
}) | ||
} | ||
|
||
async testAsync () { | ||
const data = await this.sleep(3) | ||
console.log(data) | ||
} | ||
|
||
getUserInfo(cb) { | ||
const that = this | ||
if (this.globalData.userInfo) { | ||
return this.globalData.userInfo | ||
} | ||
wepy.getUserInfo({ | ||
success (res) { | ||
that.globalData.userInfo = res.userInfo | ||
cb && cb(res.userInfo) | ||
} | ||
}) | ||
} | ||
} | ||
</script> |
74 changes: 74 additions & 0 deletions
74
packages/wepy-cli/templates/template/src/components/counter-redux.wpy
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,74 @@ | ||
<style lang="less"> | ||
.counter { | ||
text-align: left; | ||
font-size: 12px; | ||
} | ||
.count { | ||
font-size: 18px; | ||
font-weight: bold; | ||
} | ||
</style> | ||
<template> | ||
<view class="counter {{style}}"> | ||
<button @tap="plus" size="mini"> + </button> | ||
<button @tap="minus" size="mini"> - </button> | ||
<button @tap="incNum" size="mini"> INCREMENT </button> | ||
<button @tap="decNum" size="mini"> DECREMENT </button> | ||
<button @tap="asyncInc" size="mini"> ASYNC INCREMENT </button> | ||
<text class="count"> {{num}} </text> | ||
<text class="count"> {{stateNum}} </text> | ||
<text class="count"> {{asyncNum}} </text> | ||
</view> | ||
</template> | ||
<script> | ||
import wepy from 'wepy' | ||
import { connect } from 'wepy-redux' | ||
import { INCREMENT, DECREMENT } from '../store/types/counter' | ||
import { asyncInc } from '../store/actions' | ||
|
||
@connect({ | ||
stateNum (state) { | ||
return state.counter.num | ||
}, | ||
asyncNum (state) { | ||
return state.counter.asyncNum | ||
} | ||
}, { | ||
incNum: INCREMENT, | ||
decNum: DECREMENT, | ||
asyncInc | ||
}) | ||
export default class Counter extends wepy.component { | ||
props = { | ||
num: { | ||
type: [Number, String], | ||
coerce: function (v) { | ||
return +v | ||
}, | ||
default: 50 | ||
} | ||
} | ||
|
||
data = { | ||
} | ||
events = { | ||
'index-broadcast': (...args) => { | ||
let $event = args[args.length - 1] | ||
console.log(`${this.$name} receive ${$event.name} from ${$event.source.$name}`) | ||
} | ||
} | ||
|
||
methods = { | ||
plus () { | ||
this.num = this.num + 1 | ||
console.log(this.$name + ' plus tap') | ||
|
||
this.$emit('index-emit', 1, 2, 3) | ||
}, | ||
minus () { | ||
this.num = this.num - 1 | ||
console.log(this.$name + ' minus tap') | ||
} | ||
} | ||
} | ||
</script> |
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.
示例不够充分,目前只有一个
counter
组件使用了redux。需要再加入一个组件,看不同组件中的同一数据流是否存在问题。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.
这个在我的原始demo是有的,但后来我思考的是 counter 是多个实例的,所以也算是“多”个组件了