Skip to content
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

Feature(MapSingleObject): Allows to map on a single object instead of collection only #10

Merged
merged 7 commits into from
Oct 10, 2017

Conversation

emyann
Copy link
Member

@emyann emyann commented Oct 8, 2017

No breaking changes. Full backward compatible with previous versions.

Single Object Mapping

Allows to map a single object instead of collection only. The output dimension is the same as the input dimension.

To map an object, or collection before

let source = {...};
let object = Morphism(schema, [source])[0];

// Iterate on collection and map
collection.map(item => Morphism(schema,[item])[0];

To map an object, or collection now

let source = {...};
let object = Morphism(schema, source);
// → {...} output is an object
let sources = [{...}, {...}];
let ouput = Morphism(schema, sources);
// → [] output is a collection
let output = Morphism.map(Type, []);
// →Type[] output is a collection of Type
let output = Morphism.map(Type, {});
// →Type{} output is a Type object

Make low level and typed mappers functions iteratee first:

now it's possible to do:

map over a Low Level mapper (schema applied on plain objects)

let collection = [{...}, {...}];
let results = collection.map(Morphism(schema));
let collection = [{...}];
const mapper = Morphism(schema);
let results = collection.map(mapper);

map over a Typed mapper (schema applied on Type)

let collection = [{...}, {...}];
class Type {}
let mapper = Morphism.register(Type);
let results = collection.map(mapper);
let collection = [{...}, {...}];
class Type {}
let results = collection.map(Morphism.map(Type));

Misc

- Add defensive programming on falsy and empty input
- Refactor to split low level values transformation into a function. Morphism currying function is used as a router to Typed transformations, and Plain Object transformation
- Add more Unit tests cases from @landr/Falcor UTs (+700UTs)
@emyann emyann self-assigned this Oct 8, 2017
@coveralls
Copy link

coveralls commented Oct 8, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 4a476a5 on feature/Map-Single-Object-And-Refactoring into df023b7 on master.

@emyann
Copy link
Member Author

emyann commented Oct 8, 2017

@ludovicthomas This PR might interest you. I improved usability as already discussed. Tested with our Falcor implementation, it's fully backward compatible. No need for a review but I won't refuse a pass if you have some time :)

@nobrainr nobrainr deleted a comment from coveralls Oct 9, 2017
@nobrainr nobrainr deleted a comment from coveralls Oct 9, 2017
@nobrainr nobrainr deleted a comment from coveralls Oct 9, 2017
@nobrainr nobrainr deleted a comment from coveralls Oct 9, 2017
@nobrainr nobrainr deleted a comment from coveralls Oct 10, 2017
@nobrainr nobrainr deleted a comment from coveralls Oct 10, 2017
@nobrainr nobrainr deleted a comment from coveralls Oct 10, 2017
@nobrainr nobrainr deleted a comment from coveralls Oct 10, 2017
@nobrainr nobrainr deleted a comment from coveralls Oct 10, 2017
@nobrainr nobrainr deleted a comment from coveralls Oct 10, 2017
@nobrainr nobrainr deleted a comment from coveralls Oct 10, 2017
@coveralls
Copy link

coveralls commented Oct 10, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 2499f0c on feature/Map-Single-Object-And-Refactoring into df023b7 on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 2499f0c on feature/Map-Single-Object-And-Refactoring into df023b7 on master.

@emyann emyann merged commit 2499f0c into master Oct 10, 2017
@ludovicthomas
Copy link
Collaborator

ludovicthomas commented Oct 12, 2017

Sorry for late feedback. Nice work! Thanks for the update.

@emyann emyann deleted the feature/Map-Single-Object-And-Refactoring branch January 10, 2019 08:23
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.

None yet

3 participants