faurewu / zoro Goto Github PK
View Code? Open in Web Editor NEWA Simple Redux Framework, For Weapp, React App and Other.
Home Page: https://faurewu.github.io/zoro/
License: MIT License
A Simple Redux Framework, For Weapp, React App and Other.
Home Page: https://faurewu.github.io/zoro/
License: MIT License
thirdScriptError
sdk uncaught third Error
Cannot read property 'prototype' of undefined
TypeError: Cannot read property 'prototype' of undefined
at runInContext (http://127.0.0.1:53914/appservice/npm/lodash/lodash.js:1435:27)
at http://127.0.0.1:53914/appservice/npm/lodash/lodash.js:17078:11
at http://127.0.0.1:53914/appservice/npm/lodash/lodash.js:17105:3
at require (http://127.0.0.1:53914/appservice/__dev__/WAService.js:22:3705)
at http://127.0.0.1:53914/appservice/__dev__/WAService.js:22:3419
at http://127.0.0.1:53914/appservice/npm/zoro/zoro.js:1:271
at require (http://127.0.0.1:53914/appservice/__dev__/WAService.js:22:3705)
at http://127.0.0.1:53914/appservice/__dev__/WAService.js:22:3419
at http://127.0.0.1:53914/appservice/app.js:15:13
at require (http://127.0.0.1:53914/appservice/__dev__/WAService.js:22:3705)
希望在typescript项目中使用这个,应该怎样设置自动补全呢?
按照接入taro教程搭建一个demo,
组件中无法正常显示redux中的state,
需要dispatch触发才能正常显示。
Taro版本 2.0.4
connect map之后的数据直接setdata了,请问如何handle state change做额外的操作?
框架:Taro
store.ts
导出:store
、app
import zoro from '@opcjs/zoro' // 引入zoro
import { createLoading, createMixin } from '@opcjs/zoro-plugin'
import { index, counter } from '../models/index'
// import configStore from './store'
// 通过zoro创建store,移除原有的代码
const app = zoro()
// 加载model
app.model(counter)
app.model(index)
// 使用Loading插件
app.use(createLoading())
// 使用Mixin
app.use(createMixin({
namespace: 'common',
state: {},
reducers: {
updateState (action, state) {
console.log({ state, action })
return { ...state, ...action.payload }
}
},
effects: {
}
}))
const store = app.start(false)
export { store, app }
app.tsx
执行setup
:
import { store, app } from './utils/store'
...
componentDidMount () {
app.setup()
}
...
定义的模型models.ts
如下:
import * as indexApi from './service';
function delay(time) {
return new Promise(resolve => {
setTimeout(resolve, time)
})
}
export default {
namespace: 'index',
state: {
search: {
placeholder: '',
hots: ['1', '2', '3', '4', '5']
},
pictures: [{}],
togethers: [{}, {}],
shops: [{}, {}, {}, {}]
},
mixins: ['common'],
effects: {
async asyncAdd(action, { put }) {
await delay(2000)
put({ type: 'add' })
},
async get ({}, { put }) {
const { success, message, data } = await indexApi.get()
console.log({ data })
if (success) {
put({
type: 'updateState',
payload: {
...data
}
})
}
}
},
reducers: {
}
}
问题:
在get
这个effect
中,想通过调用common
里面的updateState
更新数据,但是页面并没有反映。
而在同一个models.ts
里面的reducers
中写同样的updateState
,页面会更新。
升级到zoro 1.1.11版本,按照最新的写法,发现异步操作无法触发。同步正常。但是还需本地写一个函数转一下,再传递。
Taro 版本 beta10。
import Taro, { Component } from '@tarojs/taro';
import { View, Text, Button } from '@tarojs/components';
import { connect } from '@tarojs/redux';
import { createDispatcher } from 'roronoa-zoro';
import * as MODELS from '../../../constants/models';
import Counter from '../../../components/counter/presenter';
const counterDispatcher = createDispatcher(MODELS.MODEL_COUNTER);
@connect(state => ({
count: state[MODELS.MODEL_COUNTER].count,
parts: state[MODELS.MODEL_COUNTER].bodyParts
}))
export default class CounterDemo extends Component {
config = {
navigationBarTitleText: '计数器demo'
};
add = () => {
counterDispatcher.add();
};
dec = () => {
counterDispatcher.dec();
};
queryBody = () => {
counterDispatcher.queryBodyParts;
}
render() {
console.log(this.props);
const { count } = this.props;
return (
<View>
<Counter count={count} onAdd={this.add} onDec={this.dec} />
<View style="height: 5px" />
<Button onClick={this.queryBody}>异步加载后台数据</Button>
{this.props.parts.map(item => {
return (
<View key={item.id}>
<Text key={item.id}>{item.name}</Text>
</View>
);
})}
</View>
);
}
}
import * as MODELS from '../constants/models';
import * as API from '../services/demo';
export default {
namespace: MODELS.MODEL_COUNTER,
state: {
count: 0,
bodyParts: []
},
effects: {
async queryBodyParts({}, { put }) {
const ret = await API.getBodyParts();
put({
type: 'getBodyParts',
payload: ret
});
}
},
reducers: {
getBodyParts({ payload }, state) {
return {
...state,
bodyParts: payload
};
},
add({}, state) {
console.log('add-----');
return {
...state,
count: state.count + 1
};
},
dec({}, state) {
console.log('dec-----');
return {
...state,
count: state.count - 1
};
}
}
};
能不能支持这种写法dispatcher({
type:'flights/getBannerAction',
payload:{name:1}
})
我折腾半天,没弄成功,也不确信是否支持。
麻烦作者花点时间,采用最新版本Taro,做个基本的weapp+h5+react native的例子,
谢谢!
小程序怎么集成redux-devtools
Taro框架中引入zoro,连接后,方法无法直接从props使用,必须在本地定义一个函数,间接使用。
add = () => {
this.props.add();
};
dec = () => {
this.props.dec();
};
render() {
const { count } = this.props;
return (
<View>
<Counter count={count} onAdd={this.props.add} onDec={this.dec} />
这个时候,onAdd这个无法使用,其它case都是正常的。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.