1,205 questions
1
vote
1
answer
68
views
React component will not update when using redux and createSelector, not detecting UI changes
I created a selector of users in a group in my immutable redux state:
import { useStore } from 'react-redux';
import { createSelector } from '@reduxjs/toolkit'
const selectGroup = (state) => state....
2
votes
1
answer
110
views
Why are Maps allowed where an OrderedMap is expected? (TypeScript API Design Question)
To clarify: This is nominally about Immutable.js' Map/OrderedMap, though the essence of the question is general to any TypeScript API (/structurally typed language).
I think I understand technically ...
0
votes
2
answers
176
views
Unknown type in Immutable object
I am using Typescript 5.3.3 and I have reducer code that generates ts(2345) errors.
The reducer looks like this:
const initialState = Immutable.fromJS({
isLoading: false,
})
const myReducer = (...
0
votes
1
answer
66
views
How to convert a nested data structure to an immutable one in a type-safe way when using Immutable?
Immutable comes with the fromJs function that transforms a regular nested data structure to an immutable one. My problem is that I can't get it to work nicely with Typescript. This is what I have:
...
0
votes
1
answer
460
views
ts(2532) Object possibly undefined after undefined check
After upgrading our Typescript and Immutable libraries, I am seeing the error Object is possibly 'undefined'.ts(2532) in many places across our codebase even when there is an undefined check prior to ...
0
votes
0
answers
297
views
Check if a string exists in an Immutable.Set<string[]>
Here is a mock of what I have tried with each outcome... I've read over the documentation and it seems like at least some of these things should work. Not sure what I'm doing wrong.
function getMatch(
...
1
vote
1
answer
243
views
Avoiding type assertion when using useSelector with Redux, Immutable.js, and TypeScript
I'm currently working with a combination of Redux, Immutable.js, and TypeScript. I'm having trouble getting proper types from the useSelector hook, and I've resorted to using type assertions. I ...
0
votes
1
answer
176
views
testing issue in redux saga method using jest
I am testing my redux saga method using jest. I am facing some issues. Attaching the saga method, test case & the console response.
Let me know where I missed it. Tried lots of googling. But ...
1
vote
2
answers
2k
views
Update deeply nested state object in redux without spread operator
I've been breaking my head for a week or something with this !!
My redux state looks similar to this
{
data: {
chunk_1: {
deep: {
message: "Hi"
}
},
...
0
votes
1
answer
64
views
Is there a way to set and push at the same time in a Redux action?
case 'MODIFY_NODES': {
if (action.payload.nodes) {
for (const node of action.payload.nodes) {
const setNodes = action.payload.nodes.filter(n => state.findIndex((item) => ...
0
votes
1
answer
278
views
How do I grab value from nested immutable Map Object? Please Answer
I am trying to grab data from an array of objects called "nodes".
I've console logged:
console.log(props.mapValues.get('entries'))
to grab the object but it returns an array length of 0.
...
0
votes
0
answers
44
views
What are the advantages of immutable data? [duplicate]
What are the advantages of using immutable libraries like immer.js or immutable.js? What is the difference between making changes to a draft of an object or making changes to a duplicate of the ...
2
votes
2
answers
647
views
How to access value in immutable object/map in JS?
I am trying to grab the 'message' value but it is returning undefined when I use this:
console.log('message: ', props.information.getIn(['_root', 'entries']))
To console log the data below I use this ...
0
votes
1
answer
269
views
Immutable.js difference between toJSON() and toObject() on Record
With the release of Immutable v4, there has been some api changes.
toJS(): any became toJS(): {[key: string]: unknown}
From what I understand it has been replaced by toJSON() but what's the difference ...
0
votes
2
answers
934
views
Javascript - Grouping and filtering a list of lists
I have a value events which is a list of lists with maps that look like this:
[
[
{
"packageId": "2721",
"eventTime": "2022-03-...
2
votes
3
answers
181
views
Javascript - Filtering out all map elements if a map with the same type already exists in a list
I have a value events of a type Map<number, List<Event>>, I am flattening this value like this:
const flatEvents = events.valueSeq().flatMap(event => event.values()).toList()
The value ...
0
votes
1
answer
1k
views
Js immutable - how to flatten a map to a Set<number>
I have a value shipments that is of a type Map<number, Shipment>, Shipment has a property packageIds which is of a type Set<number>. When I have multiple shipments I would like to go ...
0
votes
0
answers
1k
views
Infinite nesting object with yup validation?
I have an object that may contain children of the same type of object, potentially making it infinite nested.
{
command: Yup.string(),
children: [
{
val1: Yup.string()...
0
votes
0
answers
141
views
Typescript - Expression is not callable but fixed by a guard/narrowing
Here is my function.
export class GetPipe {
public transform<K, V>(
list:
| Array<V>
| List<V>
| Map<K, V>
| ...
0
votes
1
answer
231
views
How to successfully render an array of images from the Nasa Mars Rover api
I'm working on a project that consumes data from the Nasa Mars Rover api and keeps it in a store with Immutable.js store. The data is correctly updated in the store, and i'm able to access the data ...
1
vote
0
answers
1k
views
React How to delete it only when you press the delete button and then press the OK button
I want to receive this JSON form from the server and add it automatically in the dialog.
I want to automatically show the input item coffee, 15... in the dialog.
Q1) I want to delete it only when I ...
0
votes
1
answer
61
views
Does immutablejs allow searching with a reference type
I have a piece of code that looks like this
const { Map } = require('[email protected]')
let map = new Map().setIn(["user",["alex","country"]],"Poland")
map....
0
votes
2
answers
119
views
Redux data not rerendering when setting value within object (Immutable.js)
I have an immutable.js Map stored in Redux that is structured like:
reduxObject: {
details: {}
...
objectToChange: {
myPosts: [{
name: 'someName',
link: 'someLink',
...
-1
votes
1
answer
291
views
Question on Best practices: Immutability and re-rendering with React Native
I have created an immutable map and am currently using it with redux and i have some general questions about immutability. From what I understand, when passing props down to a component the props do ...
1
vote
2
answers
2k
views
Type 'string' is not assignable to type keyof in Immutable.js
I got this typing error when trying to use immutable js reviver from fromJS function.
Check this TS playground, I could reproduce it there.
interface User {
name: string;
age: number;
}
// Taken ...
0
votes
1
answer
99
views
What is the time complexity for Immutable.JS's deleteIn?
Just curious, what is the time complexity for Immutable.JS's deleteIn? In the documentation, it says that gets and sets are O(log32 N) for immutable.Map. Assume that we are not deleting from an array, ...
0
votes
1
answer
54
views
Dynamically set value to a record without a $FlowFixMe
I have code that looks similar to this
const attr = event.target.value;
const query = filter.merge({
[attr]: !filter[attr]
});
where filter is a Immutable Record. Flow complains because an index ...
1
vote
0
answers
159
views
How to insert/update Immutable.Map of Immutable.Map in JavaScript?
I have a nested Immutable.Map of Immutable.Map type defined as follows:
export type Data = Immutable.Map<string, Immutable.Map<string, string>>;
const nested : Data = Immutable.Map();
...
1
vote
0
answers
928
views
Reason: `object` ("[object Object]") cannot be serialized as JSON. Please only return JSON serializable data types
I am using next.js immutable Js and redux saga.
Error: Error serializing .initialState.ui returned from
getServerSideProps in "/me/profile-setting". Reason: object
("[object Object]&...
0
votes
0
answers
363
views
React/Redux - getting json data from fetch request gives undefined for property in response body
I have a fetch request where I am getting a data object that has an items array in it.
export const getItems = (searchString: string, limit?: string, offset?: string) => (dispatch: ThunkDispatch) =&...
2
votes
4
answers
180
views
How to make a promise object immutable when setting different states in Javascript?
I'm working with React/Redux and want to use the same Promise result to set two different states. Here's my code:
useEffect(() => {
fetchData().then((resp) => {
Object.freeze(resp);
...
1
vote
1
answer
6k
views
"First Load JS" size problem Next.js. (Using immutable.js)
In my project(Next.js v10), the immutable library is used to work with redux. Now I tackled the issue of optimization, because I ran into the problem of "red" first load js.
I am not very ...
1
vote
1
answer
161
views
Appending new Immutable Map value to Immutable List
I have below a piece of code wherein I need to push a new Immutable Map value to an Immutable List on each forEach iteration. The flow goes into if condition as expected, but nothing is being pushed ...
1
vote
2
answers
920
views
Update immutable js nested object with new value
I have 2 Immutable Object. and the structure is like below
const state = fromJS({
"a":"value1",
"b":{
"c":"value2"
...
0
votes
1
answer
926
views
Typing a recursive Immutable js Record in Typescript
I am trying to represent a tree-like data structure using immutable js and typescript. Right now, I am using normal vanilla js objects to represent the nodes in the tree. Here is the type signature.
...
0
votes
3
answers
211
views
Immutable JS - converting a collection of Maps to a List
I have the following structure in the project im working on (uses immutable JS):
data :[{name: 'john', surname: 'smith', children: [{name: 'sam'}, {name: 'ben'}]},
{name: 'jane', surname: '...
0
votes
2
answers
1k
views
Merging redux objects
I am using redux to persist state for a React.JS app.
The state keeps objects named event, which look-like {id: 2, title: 'my title', dates: [{start: '02-05-2021', end: '02-05-2021'}] } hashed by ...
0
votes
2
answers
115
views
Map of immutable list is only updating the last index
I have this declaration:
const players = immutable.fromJS({
enabled: true,
contract,
})
and I have a checkbox that basically toggles the enabled to true/false.
I also have 'Enabled All' ...
0
votes
2
answers
159
views
Why is it possible to mutate the value of an item in an Immutable.List?
Immutable.List does not seem to prevent you treating it as a mutable array:
const Immutable =require( 'immutable');
const l = Immutable.List([1,2,3,4,5]);
l[4] = 9;
console.log(l[4], l.get(4)) // ...
0
votes
1
answer
371
views
Cannot import RecordFactory from immutable.js
I'm not sure why but I'm getting an error when I'm trying to import 'RecordFactory' from immutable.js:
The error is: Module '"immutable"' has no exported member 'RecordFactory'.ts(2305)
Env:...
0
votes
2
answers
568
views
how to check if all the keys of a immutable map have value
const [fieldValues, updateFieldValues] = useState(fromJS({
imageName: '',
tags: [],
password: '',
}));
const handleButtonClick = () => {
const res = // logic to find which field/...
0
votes
1
answer
243
views
Redux unexpected behaviour | create empty object if not found
I am debugging an app, there is an existing redux reducer which sets some data of store object. Now when i dispatch action for this reducer before the relevant object is initialised it still works and ...
1
vote
2
answers
718
views
Retrieve the value of a List/Map the proper way with Immutable JS in TypeScript
I've been working with Immutable JS for a few months. And I really like the functionality it gives. But I've been doing something I don't like over and over again. It has to do with retrieving a value ...
0
votes
2
answers
38
views
JS Object Field Extraction from an Array
This is my Product
[
{
"quantity": 8,
"size": "S",
"product": {
"_id": "607283d971fbe12de4e42ebe",
"title&...
1
vote
1
answer
568
views
Immutable.js Combine with React Typescript
I'm having a hard time refactor my reducers to TS since I'm using Immutable.js in my project
This is my reducer:
export interface DashboardState {
componentId: number | null;
dashboard: number | ...
0
votes
1
answer
54
views
Is Immutable.js v4.0.0-rc.12 ready for production?
I would like to use immutable.js, and see that v4.0.0 is at rc.12. That version string seems to indicate that v4.0.0 is not yet released. Is that because there is a problem with v4.0.0, and we should ...
0
votes
1
answer
154
views
how to define an array of certain size immutable.js
I have this type:
type Route<A> = [A] | [A, A] | [A,A,A]
So when I define routes like this:
const r: Route<number> = [1,2],
r2: Route<number> = [1,2];
and I put them in a set:
...
0
votes
1
answer
408
views
Merge state objects in Redux
My state consists of settings selected by a user to view charts in the application. Each time a user logs in I get their respective settings from the database. I also have an initial state defined in ...
0
votes
1
answer
118
views
How to define an array of string and number or a tuple in immutable.js
In typescript I can define an array of a number and string like this:
type A = [number, string]
I decided to use Immutable.js now how do I define this type using an Immutable List.
Something like ...
0
votes
1
answer
319
views
What's the best way to intersect more than two sets in immutable.js?
immutable.js has a Set object, and you can find the intersection of two sets via set1.intersect(set2), but what if I have an arbitrarily long array of sets [set1, set2, set3, set4,...] and I want to ...