Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Records support #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 29, 2015
Merged

Records support #9

merged 2 commits into from
Dec 29, 2015

Conversation

corbt
Copy link
Collaborator

@corbt corbt commented Dec 29, 2015

This PR adds record support as discussed in #7. It's based on the work by @thomasboyt in his fork, with a few modifications:

  1. Nesting Records and other ImmutableJS objects within Records is supported.
  2. Filter has been disabled on Record instances. It isn't a method that ImmutableJS supports on records anyway, and has unexpected behavior. However, a filter predicate applied to a Record instance will successfully filter nested ImmutableJS objects that implement filter such as Map (covered in the tests).
  3. If no Record constructor is passed to the library for a particular Record instance, it will default to encoding the record as a Map (it still will throw an error though if you try to decode a Record without passing the correct constructor).
  4. I've also added documentation to the README.

I think this covers everything @glenjamin asked for to merge a PR; if there's anything else necessary I'm happy to make changes!

@glenjamin
Copy link
Owner

Excellent work! will dive in and review now.

Let me know if you wont have time to follow up, and I can probably finish myself in that case.

@@ -61,3 +61,21 @@ Convert a JSON representation back into an immutable object
### `transit.withFilter(function) => transit`

Create a modified version of the transit API that deeply applies the provided filter function to all immutable collections before serialising. Can be used to exclude entries.

### `transit.withRecords([recordClasses], optionalFilterFunction) => transit`
Copy link
Owner

Choose a reason for hiding this comment

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

I'd be tempted to leave out the filter argument, but allow withRecords(records).withFilter(filter) instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah a fluent API like that makes more sense to me as well, I just left it this way because it's how @thomasboyt implemented it. I can change it though.

@glenjamin
Copy link
Owner

Let me know if any of that is unclear, and feel free to disagree! 😄

@corbt corbt force-pushed the records-support branch 2 times, most recently from 8dc0b05 to 2dcf14b Compare December 29, 2015 22:59
@corbt
Copy link
Collaborator Author

corbt commented Dec 29, 2015

Ok think I've covered everything you brought up. I'll open a PR on immutableJS for the recordName thing, but I don't think it's worth waiting on that to get this functionality merged.

@@ -61,3 +61,21 @@ Convert a JSON representation back into an immutable object
### `transit.withFilter(function) => transit`

Create a modified version of the transit API that deeply applies the provided filter function to all immutable collections before serialising. Can be used to exclude entries.

### `transit.withRecords([recordClasses])[.withFilter(function)] => transit`
Copy link
Owner

Choose a reason for hiding this comment

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

do you think it would be straightforward to generalise so that these can be used in either order - and shrink down to only one place for creating the public API?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I'm sure there's a good way to do that. It's getting late here in Spain and my brain stops working so well. :P Let me think about the best way to implement this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

After further consideration and a bit of experimentation I haven't found a way I'm happy with to make this work while both preserving the existing semantics and not complicating the code internally. That doesn't mean it isn't possible, just that I don't see the way to do it. 😄 Given how infrequently I suspect someone will want to both set a filter and deal with Records, and given that the current solution works just fine, I'm inclined to leave it how it is right now.

Copy link
Owner

Choose a reason for hiding this comment

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

No worries, I might take a crack at this myself - I think there should be a way to achieve this and end up with less code 😄

@glenjamin
Copy link
Owner

Nice work on this, that was fast!

glenjamin added a commit that referenced this pull request Dec 29, 2015
@glenjamin glenjamin merged commit 326a94c into glenjamin:master Dec 29, 2015
@corbt
Copy link
Collaborator Author

corbt commented Dec 30, 2015

Hey, would you mind cutting a new release with this functionality? I need it available so I can make a PR for another module in my dependency chain, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants