Skip to content

Commit

Permalink
feat(wx-mobx wx-mobx-react): 添加mobx相关库:mobx, mobx-react
Browse files Browse the repository at this point in the history
  • Loading branch information
ykforerlang committed Jul 2, 2019
1 parent fe92539 commit 5ee22b0
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 38 deletions.
33 changes: 2 additions & 31 deletions packages/wx-mobx-react/miniprogram_dist/Provider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Children, Component } from "react"
import { polyfill } from "react-lifecycles-compat"
import { Component } from "@areslabs/wx-react"
import * as PropTypes from "./propTypes"

const specialReactKeys = { children: true, key: true, ref: true }
Expand All @@ -19,9 +18,7 @@ class Provider extends Component {
copyStores(props, this.state)
}

render() {
return Children.only(this.props.children)
}
render() {}

getChildContext() {
const stores = {}
Expand All @@ -33,30 +30,6 @@ class Provider extends Component {
mobxStores: stores
}
}

static getDerivedStateFromProps(nextProps, prevState) {
if (!nextProps) return null
if (!prevState) return nextProps

// Maybe this warning is too aggressive?
if (
Object.keys(nextProps).filter(validStoreName).length !==
Object.keys(prevState).filter(validStoreName).length
)
console.warn(
"MobX Provider: The set of provided stores has changed. Please avoid changing stores as the change might not propagate to all children"
)
if (!nextProps.suppressChangedStoreWarning)
for (let key in nextProps)
if (validStoreName(key) && prevState[key] !== nextProps[key])
console.warn(
"MobX Provider: Provided store '" +
key +
"' has changed. Please avoid replacing stores as the change might not propagate to all children"
)

return nextProps
}
}

function copyStores(from, to) {
Expand All @@ -68,7 +41,5 @@ function validStoreName(key) {
return !specialReactKeys[key] && key !== "suppressChangedStoreWarning"
}

// TODO: kill in next major
polyfill(Provider)

export default Provider
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from "react"
import * as React from "@areslabs/wx-react"
import { patch, newSymbol } from "./utils/utils"

const storeKey = newSymbol("disposeOnUnmount")
Expand Down
2 changes: 1 addition & 1 deletion packages/wx-mobx-react/miniprogram_dist/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spy, configure, getDebugName } from "mobx"
import { spy, configure, getDebugName } from "@areslabs/wx-mobx"
import { Component } from "@areslabs/wx-react"

export {
Expand Down
1 change: 1 addition & 0 deletions packages/wx-mobx-react/miniprogram_dist/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function createStoreInjector(grabStoresFn, component, injectNames) {
newProps.ref = this.storeRef
}

Object.assign(newProps, this.hocProps)
return createElement(component, newProps)
}
}
Expand Down
9 changes: 7 additions & 2 deletions packages/wx-mobx-react/miniprogram_dist/observer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component, PureComponent } from "@areslabs/wx-react"
import { createAtom, Reaction, _allowStateChanges, $mobx } from "mobx"
import { createAtom, Reaction, _allowStateChanges, $mobx } from "@areslabs/wx-mobx"
import hoistStatics from "./utils/hoistNonReactStatics"

import EventEmitter from "./utils/EventEmitter"
Expand Down Expand Up @@ -162,6 +162,11 @@ const reactiveMixin = {
this[mobxIsUnmounted] = true
},

componentWillMount: function() {
// observer的组件,需要调用forceUpdate更新组件,所以要设置__stateless__标志
this.__stateless__ = false
},

componentDidMount: function() {

},
Expand Down Expand Up @@ -289,7 +294,7 @@ export function observer(arg1, arg2) {
}

function mixinLifecycleEvents(target) {
;["componentDidMount", "componentWillUnmount", "componentDidUpdate"].forEach(function(
;["componentWillMount", "componentDidMount", "componentWillUnmount", "componentDidUpdate"].forEach(function(
funcName
) {
patch(target, funcName)
Expand Down
2 changes: 1 addition & 1 deletion packages/wx-mobx-react/miniprogram_dist/propTypes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isObservableArray, isObservableObject, isObservableMap, untracked } from "mobx"
import { isObservableArray, isObservableObject, isObservableMap, untracked } from "@areslabs/wx-mobx"

// Copied from React.PropTypes
function createChainableTypeChecker(validate) {
Expand Down
4 changes: 2 additions & 2 deletions packages/wx-mobx-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wx-mobx-react",
"version": "1.0.0",
"name": "@areslabs/wx-mobx-react",
"version": "0.0.3",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions packages/wx-mobx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## wx-mobx-react

The code is a copy from [mobx v4.11.0](https://github.com/mobxjs/mobx/tree/4.11.0). We made some adjustments for Wechat
1 change: 1 addition & 0 deletions packages/wx-mobx/miniprogram_dist/index.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions packages/wx-mobx/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@areslabs/wx-mobx",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

0 comments on commit 5ee22b0

Please sign in to comment.