Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
352 views
in Technique[技术] by (71.8m points)

Mobx state tree observe not working as expected

const Player = types.model({
    game_object: types.frozen()
});

const Zone = types.model({
    players: types.map(Player)
})
.actions(self => ({
    addPlayer(params) {
        const playerGameObject = new PlayerGameObject(params);
        const newPlayer = Player.create({ game_object: playerGameObject })
        self.players.set(params.socket_id, newPlayer)
    }
}))

Later on I have

observe(store.zone, "players", change => {
  console.log("Store zone players changed!!", change)
})

I am not sure why this isn't working. I've tried a similar thing with a string field instead of a Player and it did work!

Here's the code sandbox!

https://codesandbox.io/s/frosty-wave-wiy74?file=/src/index.js

question from:https://stackoverflow.com/questions/65852777/mobx-state-tree-observe-not-working-as-expected

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...