Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.
Releases
[email protected]
Minor Changes
#936
6246a3c
Thanks @NullVoxPopuli! - Theuse
import fromember-resources
now supports an alternate style of usage.This is partly to provide consistency across the different kinds of resources (and resource builders), whether or not arguments are provided.
The motivation from this change comes from trying to better align with Starbeam's composition capabilities, and "define something once, use it anywhere" approach to that composition.
For example, before, only this was possible:
That looks a little awkward, because it looks like
data
is set to a constant.In
TypeScript
, this still worked out, and the type ofdata
would be anumber
,but it still didn't look intuitive.
Now, we can do this:
The key difference here is that
data
is now aReactive<number>
, which, like acell
, has a.current
property.This is a readonly value -- however
current
can still return a mutable data structure.This style of
use
ends up extending nicely to Resources that take arguments:Another approach
I can't recommend this approach for general usage, but it is supported under SemVer (for exploration and feedback).
This should feel familiar as it looks like what we're familiar with when it comes to declaring
@tracked
properties as well as@service
s.However, this has the same problems as
@service
-- in TypeScript, it requires you to usedeclare
and specify a type, which may or may not match the actual type ofStuckClock
.Additionally, whenever we want to pass arguments to the resource, like this:
The arrow function passed to
Clock
would not have the correct this.This is confusing, because in every other situation where we use classes,
the arrow function has the same context as the instance of the class.
But due to how decorators are configured / transpiled, the
this
is actually the surrounding context aroundMyClass
, because decorators are statically applied.So... that's why I want to recommend
property = use(this, Foo)
by default.