feathers icon indicating copy to clipboard operation
feathers copied to clipboard

feat: Add `exposed` property to hook context

Open vonagam opened this issue 6 years ago • 3 comments

The idea is that unless a context object is returned from the call hooks that modify context returning properties other than result (like statusCode and dispatch or other custom ones) may be skipped as those properties will not be used outside of hooks of the call itself.

Possible alternative names: dispatching or public.

vonagam avatar Dec 10 '19 20:12 vonagam

Last one of those closings. I will rebase it when asked. Assuming that the proposition is accepted.

vonagam avatar Jul 11 '20 22:07 vonagam

Sounds good. Will definitely revisit this for the next version as well.

daffl avatar Jul 11 '20 22:07 daffl

Rebased.

vonagam avatar Oct 27 '21 09:10 vonagam

I'm going to close this one since it has now diverged quite a bit and I think this can also be handled by checking for params.provider.

daffl avatar Nov 28 '22 04:11 daffl

I'm ok with closing, since the hooks functionality was moved to separate repository and it should be added there, not here.

But no, just checking params.provider is not an option here: As you can see in "Customizing and returning the context" section, you can call function just to get a context.result (in this case context will be internal and will not be exposed to the caller) or you can call it with a context as a last argument and in this case you will receive a full context with all info exposed. Params that are set on a context are irrelevant.

So if you want to provide some info by setting/changing props on context, you may want to skip this (especially if computations are expensivish) in case that context is not exposed since nobody will see the results and they are irrelevant.

vonagam avatar Nov 28 '22 05:11 vonagam

I think then we should add it in https://github.com/feathersjs/hooks as a Symbol property you can read via context[RETURNED] (or EXPOSED or PUBLIC). From a Feathers perspective currently, I believe what is set in params.provider indicates if e.g. things context.http should be set.

daffl avatar Nov 28 '22 05:11 daffl

No real objection to it being a symbol property, thought it will be the only one and it is kinda strange, but ok.

There is nothing stopping people from passing/setting provider param in internal calls. There are use cases for that. So as a library developer I cannot be sure that presence of provider means that dispatch/http or other properties are worth computing.

vonagam avatar Nov 28 '22 05:11 vonagam