Giter VIP home page Giter VIP logo

immer-gifts's People

Contributors

mweststrate avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

immer-gifts's Issues

setState updater function is impure ?

immer-gifts/src/index.js

Lines 34 to 41 in 3a82887

const dispatch = useCallback((action, undoable = true) => {
setState(currentState => {
const [nextState, patches, inversePatches] = patchGeneratingGiftsReducer(currentState, action)
send(patches) // always send patches
if (undoable) undoStack.current.push(inversePatches) // store patches if this is undoable
return nextState
})
}, [])

I notice that in the code example above, the updater function passed to setState is impure, and when rendering app inside <React.StrictMode /> during development, react will run the updater twice facebook/react#12856 (comment)

so can we implement undo feature in a better pattern?

websocket message to client is un-parsable.

I'm not sure where it is an issue in all places, but WebSocket's message that was sent to clients is array buffer and sending it via JSON.stringify makes JSON.parse face error in useSocket

immer-gifts/server.js

Lines 25 to 33 in 39171c8

ws.on("message", function incoming(message) {
console.log(message)
history.push(...JSON.parse(message))
connections
.filter(client => client !== ws)
.forEach(client => {
client.send(message)
})
})

converting it to JSON first and then stringifying it to make it work for me.

  ws.on('message', function incoming(message) {
     history.push(...JSON.parse(message));
     connections
       .filter(client => client !== ws)
       .forEach(client => {
         client.send(JSON.stringify(JSON.parse(message)));
       });
   });

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.