Comments (6)
I agree the behaviour is inconsistent and probably undesirable. In my mind, if the source is absent the the transform should not execute. I'll have a look at it. This should work for you in the meantime:
const map = createMapper();
map
.map("foo").to("foo")
.map("foo").to("baz", foo => { if(foo) return "val: " + foo });
from map-factory.
Again, thank you for all the work you are doing.
from map-factory.
I've had a deeper look at this and I believe the current behaviour is actually correct. The logic is that once you provide a transform, map-factory can no longer guess your intention. As such, it hands over complete control to the developer to decide what to do. For an undefined
or null
you might want to create some structure...maybe you don't. I'll update the documentation to make the expected behaviour clearer.
That said, the behaviour could be modified provided that the person using map-factory can make that decision.
Something like this:
const options = {
alwaysTransform: false
};
const mapper = createMapper(options);
const source = {};
const result = mapper
.map("foo").to("foo")
.map("foo").to("baz", foo => return "val: " + foo)
.execute(source);
expect(result).to.equal(source);
Changing the default behaviour would be a breaking change so I don't want to do that.
Would that work for you?
from map-factory.
Absolutely, thank you 👍
By the way, i think the package is great and it really helps me.
from map-factory.
Glad you like it!
from map-factory.
Behaviour modification features added with 1.7.0
. See README for details.
Sorry it took so long. I had to do a major refactoring under the hood!
from map-factory.
Related Issues (20)
- Proposals- Pipeline Transformation HOT 7
- Field with getter function is not mapped HOT 2
- alwaysSet with empty Array only works as first specified mapping HOT 1
- An in-range update of code is breaking the build 🚨 HOT 2
- how to change? HOT 1
- How to set null value for non existing property HOT 2
- TypeError: map_factory_1.default is not a function HOT 1
- ref parent's property inside array HOT 1
- Parent object with null subfields HOT 1
- transform arguments are not passed correctly HOT 4
- Array of undefined values should be not trigger a set or call a transform. HOT 1
- Array of array issue HOT 5
- Mapping HOT 1
- alwaysSet not working for missing Array HOT 3
- set is not allowed when used after the map method
- inconsistent behaviour of Pipeline transformation for multiple sources HOT 1
- throws an error when the path in source is not available HOT 1
- Version 10 of node.js has been released
- A chained mapper is not reusable HOT 3
- How to append additional fields in each object in an array HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from map-factory.