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.

Question: do "previous mapper results" rely on order of keys

See original GitHub issue

Given the following code snippet from the readme:

const Composed = adopt({
  cart: <Cart />,
  user: <User />,
  shippingRates: ({ user, cart, render }) => (
    <ShippingRate zipcode={user.zipcode} items={cart.items}>
      {render}
    </ShippingRate>
  )
})

How do you know in which order to apply the render prop components? Does this rely on the order of keys returned from Object.keys(mapper) call here?

As far as I know, object property order is not guaranteed. Asking because I’d love to use this library, but wondering if this could lead to some nasty (maybe cross browser) bugs.

Example of what could go wrong

Edit pw5kkjr9n0

const First = ({ children }: FirstProps) => children("foo");
const Second = ({ first, children }: SecondProps) => children(`${first}bar`);
const Display = ({ first, second }: DisplayProps) => (
  <div>
    First: {first}
    <br />
    Second: {second}
  </div>
);

const Composed = adopt({
  first: <First />,
  second: ({ first, render }) => <Second first={first}>{render}</Second>
});

const ComposedInverse = adopt({
  second: ({ first, render }) => <Second first={first}>{render}</Second>
  first: <First />,
});

const App = () => (
  <div style={styles}>
    <h3>Correct order</h3>
    <Composed>
      {({ first, second }) => <Display first={first} second={second} />}
    </Composed>

    <h3>Inversed</h3>
    <ComposedInverse>
      {({ first, second }) => <Display first={first} second={second} />}
    </ComposedInverse>
  </div>
);

Result

image

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:5
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
lucasconstantinocommented, May 21, 2018

@edorivai thanks for the heads up, it is very much appreciated. This lib reached a point where it should definitely address these uncommon but very relevant problems, if not by fixing them, at least providing people with information for the future 😉

0reactions
edorivaicommented, Jun 30, 2018

I actually wanted to take a stab at this, only to find out that Typescript doesn’t support Map out of the box.

Meaning we have 3 options:

  1. Ship a polyfill along with this library on npm
  2. Target ES6
  3. Implement it with something other than Map

What do you guys think?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is ordering of keys and values preserved in Elixir when you ...
Maps allow any value as a key. Maps' keys do not follow any ordering. While the Elixir website clearly states that Maps do...
Read more >
Do Maps have an Reliable Relationship between keySet ...
The order of map elements is deterministic. You can rely on the order being the same in each subsequent execution of the same...
Read more >
Map - JavaScript - MDN Web Docs - Mozilla
The keys in Map are ordered in a simple, straightforward way: A Map object iterates entries, keys, and values in the order of...
Read more >
Section 4: Key Informant Interviews
Key informant interviews are qualitative in-depth interviews with people who know what is going on in the community. The purpose of key informant...
Read more >
4. Working with Key/Value Pairs - Learning Spark [Book]
We can do this by running a map() function that returns key/value pairs. ... 4-9 through 4-11 to also implement the classic distributed...
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