Code Monkey home page Code Monkey logo

Comments (1)

foxdonut avatar foxdonut commented on August 26, 2024

Excellent points!

You are correct, we are mutating the object, and we have set up a controlled way of re-rendering the view on the same object, using streams to control when the re-rendering occurs.

Later on, when using a stream of functions for updates, the nesting function is:

var nestUpdate = function(update, prop) {
  return function(func) { // this is the nested update. take the incoming func, and
    update(function(model) { // call the original update, and
      model[prop] = func(model[prop]); // call func on the nested model
      return model;
    });
  };
};

Again, we are mutating model and returning it.

The Meiosis pattern works well both with mutation and immutable objects. Because we have set up a clear, unidirectional reactive loop, mutation is unlikely to cause bugs. I did not want to prescribe immutability because it is not required for the pattern to work well.

Object.assign is used to gradually explain the concept of a stream of updates, working our way up to using a stream of functions for updating the model. Once reached, utilities such as Ramda and Lodash-FP can help with producing new objects instead of mutating existing ones. I have sections on these libraries in the Documentation. But again, I don't want to imply that immutability is a requirement.

As you said, there are some functional programming patterns that rely on immutable objects. Indeed I am trying to teach some FP concepts because they are useful with Meiosis, but there's nothing wrong with using mutation.

Thank you for your feedback, I appreciate it!

from meiosis.

Related Issues (20)

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.