tsgates / mbox

A lightweight sandbox tool for non-root users
http://pdos.csail.mit.edu/mbox/
655 stars 45 forks source link

some question about mobx, new user, thanks! #37

Closed waveheart closed 5 years ago

waveheart commented 5 years ago

I pulled wokmate's colde , the userInfo part is write like this

export default new (class {
    @observable user = {}
    ...
}

when he set the 'user', the code is like this

    @action
    setInfo (info) {
        this.user = _.merge(this.user, info)
    }

when remove the userInfo , the code is like this

    @action
    async logout () {
        await cache.remove(this.tokenKey)
        this.loggedIn = false
        this.user = {}
        this.orders = []
    }

now , my issue is this , if i just use this user.name. user.tel, ect. like this

@inject('store')
@observer
class AccountInfo extends Component {
    render () {
        const {
            navigate,
            store: {
                auth: {
                    user: {tel, name, gender}
                }
            }
        } = this.props

     return (
        <div>
            <span>{tel}</span>
           <span>{name}</span>
           <span>{gender}</span>
       </div>
    )
  }
} 

it didn't refresh , and I think it certianly should not work.

I think the code is not correct, and my questtion is : at the begining , i dont kown its keys, when logout, i should set the 'user' to empty, if i still want watch the properties of user, and refresh the component , how should i rewrite the code?

waveheart commented 5 years ago

sorry . ... wrong depository...