Giter VIP home page Giter VIP logo

Comments (8)

daffl avatar daffl commented on May 30, 2024

You should already be able to set it to null instead.

from hooks.

vonagam avatar vonagam commented on May 30, 2024

null is not undefined - they are not strictly equal and typescript won't even allow to assign null there.

from hooks.

daffl avatar daffl commented on May 30, 2024

The typing should be updated to allow null then since it should be possible. undefined is however not supported as a service return or hook result value.

from hooks.

vonagam avatar vonagam commented on May 30, 2024

But hooks are not only about services, aren't they?

Well if the official position is that undefined should not be supported as a possible return value of a function - then this can be closed.

from hooks.

daffl avatar daffl commented on May 30, 2024

That's fair. One option would be to add an UNDEFINED symbol that you can set the result to in https://github.com/feathersjs/hooks so it would be possible going forward.

from hooks.

vonagam avatar vonagam commented on May 30, 2024

Yeah, thought about it (symbol). But it creates problems when you work with arbitrary functions and set their result to result property. So now you'll need to replace their undefined with UNDEFINED and if you access context.result you need to remember about UNDEFINED and so on... (and I'm sure nobody will remember)

from hooks.

vonagam avatar vonagam commented on May 30, 2024

It creates problems when undefined can mean both things - actual return value and absence of a value.

In feathers ecosystem you control rules and you can ban undefined as a return value of services, solving the ambiguity.

But when it is about random functions (many of which will be void, so should return only undefined) - i don't think you can make it work without opening door for bugs...

I assume that you don't like the idea because of breaking nature, right? Or is there anything else against it?

from hooks.

daffl avatar daffl commented on May 30, 2024

You're right, this is a good suggestion and I don't think it would be a breaking change.

I just created a pull request in #70 that should allow to do what you are suggesting by checking if there is a property descriptor for context.result. That way if context.result is ever set to anything at all in the hook chain, the method call will be skipped.

from hooks.

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.