Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Immutable support #323

Merged
merged 19 commits into from
Dec 21, 2017
Merged

Immutable support #323

merged 19 commits into from
Dec 21, 2017

Conversation

stefvhuynh
Copy link
Contributor

@stefvhuynh stefvhuynh commented Dec 18, 2017

shallowly converts data prop from immutable object to js, preserving all props in each data point within data.

corresponding PR in victory chart: FormidableLabs/victory-chart#542

x and y accessors and other props like animate that can take a function with a datum argument will receive a shallowly converted datum (datum will be a js plain object, but the keys will be in their original forms with a few exceptions).

i.e.

x={(datum) => {
  // datum is regular js but the keys are the original immutable objects
  return datum["myNestedStructure"].get("myNestedValue") + 10;
}}
animate={
  onEnter: {
    before: (datum) => {
      // datum is regular js
      // datum.someProp will be an immutable object if it was passed in as such
    }
  }
}

const accessor = {
x: Helpers.createAccessor(props.x !== undefined ? props.x : "x"),
y: Helpers.createAccessor(props.y !== undefined ? props.y : "y"),
y0: Helpers.createAccessor(props.y0 !== undefined ? props.y0 : "y0")
};
const data = dataset.map((datum, index) => {

const data = dataset.reduce((dataArr, datum, index) => { // eslint-disable-line complexity
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using reduce here because js arrays and immutable Lists both have reduce and we can then return a regular array.

}
}
return property(key)(x);
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more of a nice-to-have. People could just always specify an accessor function if they are passing in an immutable object.

return prev;
}, this.isList(x) ? [] : {}) : x;
}
};
Copy link
Contributor Author

@stefvhuynh stefvhuynh Dec 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these methods should work for immutable@v3.8.x (current latest version) as well as for v4.0.x (in release candidate phase) when it is released.

@stefvhuynh stefvhuynh requested a review from boygirl December 19, 2017 18:37
Copy link
Contributor

@boygirl boygirl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well for me!

@boygirl boygirl merged commit c68b81f into master Dec 21, 2017
@boygirl boygirl deleted the immutable-support-2 branch December 21, 2017 19:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants