question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does not work with Object.values/Object.keys

See original GitHub issue
import memoizeState from "memoize-state";

const selector = memoizeState(s => {
  return Object.values(s.items).map(x => x.text);
});

const state = {
  items: {
    1: { text: "foo" }
  }
};

console.log(selector(state));
// expected ['foo']
// actual   ['foo']  ✅

const newState = {
  ...state,
  items: {
    ...state.items,
    2: { text: "bar" }
  }
};

console.log(selector(newState));
// expected ['foo', 'bar']
// actual   ['foo'] 🚩

Codesandbox demo

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
theKasheycommented, Apr 6, 2019

The fix was added into the underlying proxyequal, but not yet released.

1reaction
theKasheycommented, Mar 29, 2019

That’s actually a good issue. You are assessing deeply nested text property, and algorithm thinks that it’s what you are interested in - not item, but only item.text. By the same long - not items but item. Result is clear - new stuff is ignored.

It’s working for arrays, as long length property changes, but not for objects. The funny moment - it’s impossible to solve this problem with the current algorithm.

Idea - for every enumeration operation(ownKeys proxy hook) “asses” a secret property = concatenated keys, but this is not a quite ES5 polyfill compatible. I really don’t want to use old spread_guard logic.

@dai-shi - might be you have some bright ideas?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Object.keys, values, entries - The Modern JavaScript Tutorial
Object.keys(obj) – returns an array of keys. Object.values(obj) – returns an array of values. Object.entries( ...
Read more >
How to Access Object's Keys, Values, and Entries in JavaScript
Let's see what utility functions provide JavaScript to extract the keys, values, and entries from an object. 1. Object.keys() returns keys.
Read more >
Object.keys() - JavaScript - MDN Web Docs
Non-object arguments are coerced to objects. Only strings may have own enumerable properties, while all other primitives return an empty array.
Read more >
Javascript: Object have keys, but Object.keys returns empty
i got containers and courses from remote server. everything was working perfectly. now i'm trying to load data from local database. it's not...
Read more >
Improve Object.keys(object) and Object.values(object) #26901
Search Terms Suggestion When all keys and values of object is known Object.keys(object) should return array type of union of known ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found