Usually when I create a TypeScript application I follow an OOP + immutable data philosophy. So let’s suppose I have two classes with mutual reference, class A and class B. Now it’s impossible to create instance of class A, since class B is required in constructor to achieve immutability, and class B requires instance of class A. It’s required to
Tag: immutability
React setState does not update a state array value
I am trying to change the state in a class component by using setState. More specific I have a table, and I want to edit/update one of its elements. For this case, I am passing the indeces to the handleTableFieldOnChange function for the position of the value in the array. Since I know that I should not mutate the state,
How to return an Immutable object from a factory function in JavaScript
I have a basic function accepts Temperature data as an argument and then perform a simple temperature conversion operation on the data How can we perform the same functionality using without mutating the object? i.e, the function should not mutate the argument passed in, it should rather return a copy I have some helper functions to help with conversion the
Enums in Javascript with ES6
I’m rebuilding an old Java project in Javascript, and realized that there’s no good way to do enums in JS. The best I can come up with is: The const keeps Colors from being reassigned, and freezing it prevents mutating the keys and values. I’m using Symbols so that Colors.RED is not equal to 0, or anything else besides itself.
Update one of the objects in array, in an immutable way
In React’s this.state I have a property called formErrors containing the following dynamic array of objects. Let’s say I would need to update state’s object having the fieldName cityId to the valid value of true. What’s the easiest or most common way to solve this? I’m OK to use any of the libraries immutability-helper, immutable-js etc or ES6. I’ve tried
Can anyone explain me what is state and mutable data?
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. http://en.wikipedia.org/wiki/Functional_programming Can anyone explain me what is state and mutable data? Can anyone give me examples in either JAVA or JavaScript. Answer mutable suggest anything that can change, i.e. an int In java a string is