Giter Site home page Giter Site logo

Comments (6)

midknight41 avatar midknight41 commented on June 15, 2024 1

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.

apricote avatar apricote commented on June 15, 2024 1

Again, thank you for all the work you are doing.

from map-factory.

midknight41 avatar midknight41 commented on June 15, 2024

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.

apricote avatar apricote commented on June 15, 2024

Absolutely, thank you 👍

By the way, i think the package is great and it really helps me.

from map-factory.

midknight41 avatar midknight41 commented on June 15, 2024

Glad you like it!

from map-factory.

midknight41 avatar midknight41 commented on June 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.