Introducing Immer: Immutability the easy way – Hacker Noon

  • The producer function receives one argument, the draft, which is a proxy to the current state you passed in.
  • The currentState will be untouched during this process.Because immer uses structural sharing, and our example producer above didn’t modify anything, the next state above is simply the state we started with.Let’s take look at what happens when we start modifying the draft in our producer.
  • It is not too bad in this simple case, but this process has to be repeated for every action, and on every level in which we want modify something.We have to make sure to return the existing state if the reducer doesn’t do anythingWith Immer, we only need to reason…
  • Both the original reducer and the new one behave exactly the same.No strings attachedThe idea to produce the next immutable state by modifying a temporarily draft isn’t new.
  • This will create a new function that will execute the producer when it’s passed in a state.

Immutable, structurally shared data structures are a great paradigm for storing state. Especially when combined with an event-sourcing architecture. However, there is a cost to pay. In a language…
Continue reading “Introducing Immer: Immutability the easy way – Hacker Noon”

Vue.js vs. React.js: Comparing Two JavaScript UI Component Libraries

  • At a time where large MVC (model-view-controller) frameworks were cutting edge, two-way data binding was considered a feature, and SSR was mostly used for static webpages, React reversed the trend, focusing on building applications from encapsulated view components, one-way data binding, and using SSR on dynamic web pages via the…
  • Dependency tracking gives Vue’s virtual DOM a slight edge over React out of the box, because it can selectively re-render the child components that are actually affected by a change in state by default — no additional coding required.
  • In React, JSX breaks with the convention of keeping JavaScript and HTML separate, by providing a declarative XML-like syntax that allows you to create self-contained UI components that encapsulate all the instructions required to render them within the view: – – The React code above will render into a simple…
  • Under the React umbrella, we have Flux, the application architecture pattern Facebook developed as a state management solution to avoid issues like the infamous phantom unseen message bug, and Redux, a framework agnostic library for providing a simplified implementation of the Flux pattern, which replaces MVC (model-view-controller).
  • Both Vue and React are cutting edge UI component libraries that make use of a virtual DOM, embrace the components based future of web development, support SSR, and Universal JavaScript.

In this article, we’ll explore some of the key differences between the React.js and Vue.js JavaScript libraries, and learn which might be the best fit for your next web project.
Continue reading “Vue.js vs. React.js: Comparing Two JavaScript UI Component Libraries”

How to Build a Todo App Using React, Redux, and Immutable.js — SitePoint

  • This helps us get a feel for what we’re going to need our components to render:
    const dummyTodos = [
    { id: 0, isDone: true, text: ‘make components’ },
    { id: 1, isDone: false, text: ‘design actions’ },
    { id: 2, isDone: false, text: ‘implement reducer’ },
    { id: 3, isDone: false, text: ‘connect components’ }
    ];

    For this application, we’re only going to need two React components, Todo / and TodoList /.

  • js

    import React from ‘react’;

    export function Todo(props) {
    const { todo } = props;
    if(todo.isDone) {
    return strike{todo.text}/strike;
    } else {
    return span{todo.text}/span;
    }
    }

    export function TodoList(props) {
    const { todos } = props;
    return (
    div className=’todo’
    input type=’text’ placeholder=’Add todo’ /
    ul className=’todo__list’
    {todos.map(t = (
    li key={t.id} className=’todo__item’
    Todo todo={t} /
    /li
    ))}
    /ul
    /div
    );
    }

    At this point, we can test these components by creating an index.html file in the project folder and populating it with the following markup.

  • /components’;

    const dummyTodos = [
    { id: 0, isDone: true, text: ‘make components’ },
    { id: 1, isDone: false, text: ‘design actions’ },
    { id: 2, isDone: false, text: ‘implement reducer’ },
    { id: 3, isDone: false, text: ‘connect components’ }
    ];

    render(
    TodoList todos={dummyTodos} /,
    the code with npm run build, then navigate your browser to the index.html file and make sure that it’s working.

  • Our dummy data is a great place to start from, and we can easily translate it into ImmutableJS collections:
    import { List, Map } from ‘immutable’;

    const dummyTodos = List([
    Map({ id: 0, isDone: true, text: ‘make components’ }),
    Map({ id: 1, isDone: false, text: ‘design actions’ }),
    Map({ id: 2, isDone: false, text: ‘implement reducer’ }),
    Map({ id: 3, isDone: false, text: ‘connect components’ })
    ]);

    ImmutableJS maps don’t work in the same way as JavaScript’s objects, so we’ll need to make some slight tweaks to our components.

  • The mapStateToProps function takes the store’s current state as an argument (in our case, a list of todos), then it expects the return value to be an object that describes a mapping from that state to props for our wrapped component:
    function mapStateToProps(state) {
    return { todos: state };
    }

    It might help to visualize this on an instance of the wrapped React component:
    TodoList todos={state} /

    We’ll also need to supply a mapDispatchToProps function, which is passed the store’s dispatch method, so that we can use it to dispatch the actions from our action creators:
    function mapDispatchToProps(dispatch) {
    return {
    addTodo: text = dispatch(addTodo(text)),
    toggleTodo: id

Dan Prince shows how to build a Todo app using React, Redux, and Immutable.js.
Continue reading “How to Build a Todo App Using React, Redux, and Immutable.js — SitePoint”

Redux and Flux in React and Angular

On 22/09, @CodiflyVOF will give a talk at @JSValley_be in #gent!  #reactjs #angular #redux

  • Inspired by Redux, ngrx/store tackles state management for applications written in Angular 2.
  • After Kristof’s introduction on Redux and its use in React, Wout De Rooms, web & mobile engineer at Codifly, who has a background with both Redux and ngrx, will focus on the differences between both libraries and show how Redux-like state management neatly integrates in Angular 2 applications.
  • Start a Meetup Group Start a Meetup Group
  • Kristof Van Miegem, co-founder of Codifly , will explain how to manage application state in React applications with Redux.
  • We share valuable content related to the engineering of modern JavaScript applications.

Again we have an evening filled with 2 mind boggling sessions, this time on Redux.

Kristof Van Miegem, co-founder of Codifly, will explain how to manage application state in React applications with R
Continue reading “Redux and Flux in React and Angular”