Properly merge incoming props (#1265)

* rename inconsistent `passThroughProps` and `passthroughProps` to more
concise `incomingProps`

This is going to make a bit more sense in the next commits of this
branch, hold on!

* split props into `propsWeControl` and `propsTheyControl`

This will allow us to merge the props with a bit more control. Instead
of overriding every prop from the user' props with our props, we can now
merge event listeners.

* update `render` API to accept `propsWeControl` and `propsTheyControl`

* improve the merge logic

This will essentially do the exact same thing we were doing before:
```js
let props = { ...propsTheyControl, ...propsWeControl }
```

But instead of overriding everything, we will merge the event listener
related props like `onClick`, `onKeyDown`, ...

* fix typo in tests

* simplify naming

- Rename `propsWeControl` to `ourProps`
- Rename `propsTheyControl` to `theirProps`

* update changelog
This commit is contained in:
Robin Malfait
2022-03-22 17:32:11 +01:00
committed by GitHub
parent 4f8c615245
commit 3e19aa5c97
37 changed files with 398 additions and 283 deletions
@@ -19,7 +19,8 @@ describe('Default functionality', () => {
return (
<div data-testid="wrapper">
{render({
props,
ourProps: {},
theirProps: props,
slot,
defaultTag: 'div',
name: 'Dummy',
@@ -80,7 +81,8 @@ describe('Default functionality', () => {
return (
<div data-testid="wrapper">
{render({
props: { ...props, ref },
ourProps: { ref },
theirProps: props,
slot,
defaultTag: 'div',
name: 'OtherDummy',
@@ -323,7 +325,8 @@ describe('Features.Static', () => {
return (
<div data-testid="wrapper">
{render({
props: rest,
ourProps: {},
theirProps: rest,
slot,
defaultTag: 'div',
features: EnabledFeatures,
@@ -428,7 +431,8 @@ describe('Features.RenderStrategy', () => {
return (
<div data-testid="wrapper">
{render({
props: rest,
ourProps: {},
theirProps: rest,
slot,
defaultTag: 'div',
features: EnabledFeatures,
@@ -455,7 +459,8 @@ describe('Features.Static | Features.RenderStrategy', () => {
return (
<div data-testid="wrapper">
{render({
props: rest,
ourProps: {},
theirProps: rest,
slot,
defaultTag: 'div',
features: EnabledFeatures,