Skip to content

Commit

Permalink
Clean up types
Browse files Browse the repository at this point in the history
  • Loading branch information
augustjk authored and jrandolf committed May 31, 2024
1 parent 9006a2c commit 39f9a1e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/context/src/lib/decorators/consume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function consume<ValueType>({
) => {
if (typeof nameOrContext === 'object') {
// Standard decorators branch
nameOrContext.addInitializer(function (): void {
nameOrContext.addInitializer(function () {
new ContextConsumer(this, {
context,
callback: (value) => {
Expand Down
24 changes: 13 additions & 11 deletions packages/context/src/lib/decorators/provide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ export function provide<ValueType>({
}: {
context: Context<unknown, ValueType>;
}): ProvideDecorator<ValueType> {
return (<C extends ReactiveElement, V extends ValueType>(
protoOrTarget: ClassAccessorDecoratorTarget<C, V>,
nameOrContext: PropertyKey | ClassAccessorDecoratorContext<C, V>
return ((
protoOrTarget: ClassAccessorDecoratorTarget<ReactiveElement, ValueType>,
nameOrContext:
| PropertyKey
| ClassAccessorDecoratorContext<ReactiveElement, ValueType>
) => {
// Map of instances to controllers
const controllerMap = new WeakMap<
Expand All @@ -51,18 +53,18 @@ export function provide<ValueType>({
>();
if (typeof nameOrContext === 'object') {
// Standard decorators branch
nameOrContext.addInitializer(function (this: ReactiveElement) {
nameOrContext.addInitializer(function () {
controllerMap.set(this, new ContextProvider(this, {context}));
});
return {
get(this: ReactiveElement) {
return protoOrTarget.get.call(this as unknown as C);
return protoOrTarget.get.call(this);
},
set(this: ReactiveElement, value: V) {
set(this: ReactiveElement, value: ValueType) {
controllerMap.get(this)?.setValue(value);
return protoOrTarget.set.call(this as unknown as C, value);
return protoOrTarget.set.call(this, value);
},
init(this: ReactiveElement, value: V) {
init(this: ReactiveElement, value: ValueType) {
controllerMap.get(this)?.setValue(value);
return value;
},
Expand All @@ -84,10 +86,10 @@ export function provide<ValueType>({
if (descriptor === undefined) {
const valueMap = new WeakMap<ReactiveElement, ValueType>();
newDescriptor = {
get: function (this: ReactiveElement) {
get(this: ReactiveElement) {
return valueMap.get(this);
},
set: function (this: ReactiveElement, value: ValueType) {
set(this: ReactiveElement, value: ValueType) {
controllerMap.get(this)!.setValue(value);
valueMap.set(this, value);
},
Expand All @@ -98,7 +100,7 @@ export function provide<ValueType>({
const oldSetter = descriptor.set;
newDescriptor = {
...descriptor,
set: function (this: ReactiveElement, value: ValueType) {
set(this: ReactiveElement, value: ValueType) {
controllerMap.get(this)!.setValue(value);
oldSetter?.call(this, value);
},
Expand Down

0 comments on commit 39f9a1e

Please sign in to comment.