Coder Social home page Coder Social logo

cnyballk / wenaox Goto Github PK

View Code? Open in Web Editor NEW
35.0 2.0 4.0 1.05 MB

:dolphin: A light weight and good performance micro channel small program state management library

License: MIT License

JavaScript 98.05% Shell 1.95%
wechat wenaox immer weapp redux vuex diff setdata miniprograms miniprogram-component

wenaox's Issues

Cannot read property 'syncs' of undefined

import {
  Store,
  Provider
} from 'wenaox';
const state = {
  count: 0,
};
const methods = {
  syncs: {
    addCount(state, payload) {
      state.count = state.count + 1;
    },
    subtractCount(state, payload) {
      state.count = state.count - 1;
    },
  },
  asyncs: {
    async asyncAddCount(payload, rootState) {
      const c = await new Promise(resolve => {
        setTimeout(() => {
          resolve(1);
        }, 2000);
      });
      this.addCount(c);
    },
  },
};
//一个打印state改变前后的log中间件
const log = store => fn => next => payload => {
  console.group('改变前:', store.state);
  next(fn, payload);
  console.log('改变后:', store.state);
  console.groupEnd();
};
//使用Store注册store  第一个参数为控制器对象,第二个参数为中间件数组
const store = new Store({
  state,
  methods
}, [log]);


const appConfig = ({
  onLaunch: function () {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        console.log(res)
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
    // 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
          wx.getUserInfo({
            success: res => {
              // 可以将 res 发送给后台解码出 unionId
              this.globalData.userInfo = res.userInfo

              // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            }
          })
        }
      }
    })
  },
  globalData: {
    userInfo: null
  },
})

// 定义App
App(Provider(store)(appConfig));



运行后
image

options页面url参数获取的bug

控制台输入能看上一个页面传的categoryId,但是 通过this.data.categoryId拿不到值
const mapState = ({ user }, options) => ({
//userInfo: user.userInfo
...options, // 將query混入data 先注释 BUG
});
const mapMethods = ({ user }) => ({
//getGtqUserInfo: user.getGtqUserInfo,
});

const pageConfig = {
data: {
},
onLoad(options) {
this.getListData();
},
getListData() {
//获取列表数据
let { categoryId } = this.data;
console.log(888, this.data, this.data.categoryId); // BUG
console.log(888, JSON.stringify(this.data));// BUG
//空字符串查询全部
},
};
Page(orm(mapState, mapMethods)(pageConfig));

当存在模块的情况,必须使用模块来取值?

版本:最新
比如这种情况
// moduleA.js
const state = { numA:1 } const methods = { syncs: { addNumA(state,payload) { state.numA += payload } }, asyncs: {} } export default {state,methods}

// store.js
`
import {Store} from 'wenaox'
import moduleA from './module-a/index'

const state = {
num:10
}
const methods = {
syncs: {
addNum(state,payload) {
state.num += payload
}
},
asyncs: {}
}

const store = new Store({state,methods, moduleA });

export default store
`

// index.js
`
import {ormComp} from 'wenaox'

const mapState = state =>({
number: state.num,
num: state.moduleA.numA
})
const mapMethods = methods => ({
addNum: methods.addNum,
addNumA: methods.moduleA.addNumA
})

Component(ormComp(mapState,mapMethods)({
data:{},
methods:{
clickBtn() {
this.addNum(12)
},
clickBtn2() {
this.addNumA(5)
}
}
}));

`
这种情况就报错,‘Cannot read property 'numA' of undefined’,如果store.js中这样导出

const store = new Store({globle:{state,methods},moduleA }); 取值都按照模块来取值则正常

兼容性

目前发现在v6.6.7版本的微信不兼容,调试基础库2.2.0(npm从2.2.1才开始兼容),打开小程序白屏。
thirdScriptError
sdk uncaught third Error
module "models/wenaox.js" is not defined
Error: module "models/wenaox.js" is not defined

bug

微信小程序的组件使用了wenaox数据缓存,缓存的数据在页面调用asyncs内的方法更新,如果在页面中使用wx:if控制组件,组件内缓存的数据没有更新(bug)。
页面代码:

未登录
点击登录

分包后的子页面第二次无法触发onShow事件

问题描述
使用wenaox,orm连接页面后第一次进入页面正常触发onLoad,onShow事件,返回后再次进入页面后第二次只触发了onLoad事件,无触发onShow事件.
经过刚刚的测试,发现在mapState为空是就不触发onshow事件了。

const mapState = ({ user }) => ({
  // 这个不会触发onShow
});
const mapState = ({ user }) => ({
  data: user.data, // 这个正常触发onShow
});

wenaox版本: "wenaox": "^0.4.4"

page.js

import { orm } from 'wenaox';

const pageConfig = {
  data: {

  },
  onLoad() {
    console.warn('onLoad')
  },
  onShow() {
    console.warn('onShow')
  },
  onShareAppMessage() {
  },
};

Page(orm(({}) => ({}),({}) => ({}))(pageConfig));

app.json

"subpackages": [
    {
      "root": "pages/user/",
      "pages": [
        "about/index"
      ]
    }
]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.