-
Notifications
You must be signed in to change notification settings - Fork 567
RFC: Derived Contexts #266
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
base: main
Are you sure you want to change the base?
Conversation
|
@gnoff as you proposed #119, if you had any thoughts on this approach they'd be incredibly interesting. My proposal is essentially an extension to dantman's I would love to see progress towards a solution to this problem, but I don't know if you or the community in general has moved on and is no longer interested in this direction. |
View Rendered Text
Selectors for Context are an in-demand feature, but with a slightly different interface, can be made much more universally useful (.slice as proposed here is similar).
Following from functional programming techniques, this RFC proposes adding:
ReadonlyContext<T>type which is a supertype ofContext<T>without.Providerand these methods to Context:
.map, of type:<T, U>(this: ReadonlyContext<T>, fn: (data: T) => U) => ReadonlyContext<U>.apply, of type:<T, U>(this: ReadonlyContext<T>, fn: ReadonlyContext<(data: T) => U>) => ReadonlyContext<U>(I actually recommend one of its alternatives).mapallows users to refine and select their Contexts, while.applyallows users to combine multiple Contexts together. This is covered in detail in Motivation.Every call, without respect to the identity of the given argument (function / context of functions), returns a distinct Context. To be usable within renders, existing user-land techniques like WeakMap can be used to stabilize the identity of the returned Context to the identity of the given argument.
RFC 119 useContextSelector draws from much of the same motivation.