Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
174118b
WIP
justinfagnani Jun 25, 2023
936d4a4
Fix build
justinfagnani Jun 26, 2023
cf5e7f4
Ignore sync
justinfagnani Jun 26, 2023
dc88822
Fix infinite loop
justinfagnani Jun 26, 2023
8e54d06
property and state tests passing
justinfagnani Jun 26, 2023
f75b0d1
ignore sync
justinfagnani Jun 26, 2023
ed700f3
all decorator tests passing
justinfagnani Jun 26, 2023
aacfa06
All tests passing
justinfagnani Jun 26, 2023
d41208a
Fix build
justinfagnani Jun 26, 2023
f9e9950
Don't reflect initial property values
justinfagnani Jun 26, 2023
6e22756
Fourth arg to requestUpdate must be an options bag to distinguish uns…
rictic Jul 10, 2023
16e0af9
Add standard decorators to @lit-labs/context
rictic Jul 8, 2023
0f5a543
Add a five arg variant of requestUpdate
rictic Jul 11, 2023
4bf3f6b
Add explicit legacy decorator modules.
rictic Jul 12, 2023
d5e6fc9
Update ignore files
rictic Jul 12, 2023
70c34e9
Merge branch '3.0' into standard-decorators
justinfagnani Jul 31, 2023
5106169
Fix types
justinfagnani Jul 31, 2023
fcaca77
Update package-lock
justinfagnani Jul 31, 2023
b482f33
Add legacy-decorators to build output
justinfagnani Jul 31, 2023
b5459e3
Add legacy-decorators/ to build
justinfagnani Jul 31, 2023
4913342
Update lit-core check size limit to 15155
justinfagnani Jul 31, 2023
9d33f8b
Use typescript@4.9 where necessary
justinfagnani Jul 31, 2023
d54a3d0
Use typescript 5.2.3 in localize-tools
justinfagnani Aug 1, 2023
f162b3c
Fix build
justinfagnani Aug 1, 2023
db073ac
Merge branch '3.0' into standard-decorators
justinfagnani Aug 12, 2023
1eb08b5
Update typescript to fix build
justinfagnani Aug 12, 2023
7f91515
Merge branch '3.0' into standard-decorators
justinfagnani Aug 14, 2023
f251a6b
Update how initial values are handled
justinfagnani Aug 15, 2023
724306b
Update expectedLitCoreSize
justinfagnani Aug 15, 2023
35fb53c
Address feedback
justinfagnani Aug 16, 2023
a26a59e
Revert change to WTR config
justinfagnani Aug 16, 2023
04c306c
address feedback
justinfagnani Aug 16, 2023
1574500
remove console.log
justinfagnani Aug 16, 2023
0713495
Add decorator re-export files to lit and lit-element
justinfagnani Aug 16, 2023
e6dabc0
Update gitignore files
justinfagnani Aug 16, 2023
439dffb
Update to typescript@5.2.0-beta
justinfagnani Aug 16, 2023
f32bc2f
Update expectedLitCoreSize
justinfagnani Aug 16, 2023
4712d3d
Delete compiler that should be ignored
justinfagnani Aug 16, 2023
74694f8
Update cli's typescript version
justinfagnani Aug 16, 2023
d0f66b7
Address feedback
justinfagnani Aug 17, 2023
7cb1472
Address feedback
justinfagnani Aug 18, 2023
8c671d1
Make @queryAll always return a NodeList
justinfagnani Aug 18, 2023
e707e68
Remove @queryAsync from standard decorators
justinfagnani Aug 18, 2023
c42e980
Move shadowed reactive property stash to dev mode
justinfagnani Aug 18, 2023
2d451c1
Remove node exports from packages that don't have them
justinfagnani Aug 18, 2023
e7760ee
Merge branch '3.0' into standard-decorators
justinfagnani Aug 18, 2023
5593b88
Update package lock
justinfagnani Aug 18, 2023
707d69b
Remove exports of removed query-async decorator
justinfagnani Aug 18, 2023
5a1c895
Update expectedLitCoreSize to 15012
justinfagnani Aug 18, 2023
4896728
Address feedback
justinfagnani Aug 22, 2023
562f044
Merge branch 'standard-decorators' into 3.0-context-std-decorators
rictic Aug 24, 2023
7f5ce4e
Fix provide with an auto accessor missing the initial value
rictic Aug 24, 2023
37eb5b0
Add tests of consuming and providing with #private fields
rictic Aug 24, 2023
bf8ca6a
Merge branch '3.0' into 3.0-context-std-decorators
justinfagnani Aug 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ packages/labs/context/test/
packages/labs/context/node_modules/
packages/labs/context/lib/
packages/labs/context/index.*
packages/labs/context/context.*
packages/labs/context/legacy-decorators.*
packages/labs/context/std-decorators.*

packages/labs/eleventy-plugin-lit/development/
packages/labs/eleventy-plugin-lit/demo/_site/
packages/labs/eleventy-plugin-lit/demo/_js/*.bundle.js
Expand Down
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ packages/labs/context/test/
packages/labs/context/node_modules/
packages/labs/context/lib/
packages/labs/context/index.*
packages/labs/context/context.*
packages/labs/context/legacy-decorators.*
packages/labs/context/std-decorators.*

packages/labs/eleventy-plugin-lit/development/
packages/labs/eleventy-plugin-lit/demo/_site/
packages/labs/eleventy-plugin-lit/demo/_js/*.bundle.js
Expand Down
16 changes: 15 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/labs/context/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/node_modules/
/lib/
/index.*
/context.*
/legacy-decorators.*
/std-decorators.*
19 changes: 18 additions & 1 deletion packages/labs/context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
"types": "./development/index.d.ts",
"development": "./development/index.js",
"default": "./index.js"
},
"./std-decorators.js": {
"types": "./development/std-decorators.d.ts",
"development": "./development/std-decorators.js",
"default": "./std-decorators.js"
},
"./legacy-decorators.js": {
"types": "./development/legacy-decorators.d.ts",
"development": "./development/legacy-decorators.js",
"default": "./legacy-decorators.js"
}
},
"files": [
Expand Down Expand Up @@ -53,6 +63,11 @@
]
},
"build:ts": {
"dependencies": [
"build:ts-main"
]
},
"build:ts-main": {
"command": "tsc --build --pretty",
"dependencies": [
"../../lit:build:ts:types",
Expand All @@ -65,6 +80,7 @@
],
"output": [
"development",
"!development/test/legacy-decorators",
"tsconfig.tsbuildinfo"
]
},
Expand Down Expand Up @@ -151,7 +167,8 @@
"@esm-bundle/chai": "^4.3.4-fix.0",
"@lit-internal/scripts": "^1.0.1-pre.0",
"@lit-labs/testing": "^0.2.2-pre.0",
"@types/trusted-types": "^2.0.2"
"@types/trusted-types": "^2.0.2",
"typescript": "^5.2.0-beta"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed now?

},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/labs/context/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {createRequire} from 'module';

export default litProdConfig({
packageName: createRequire(import.meta.url)('./package.json').name,
entryPoints: ['index'],
entryPoints: ['index', 'legacy-decorators', 'std-decorators'],
external: [
'@lit/reactive-element',
'@lit/reactive-element/decorators/base.js',
Expand Down
2 changes: 2 additions & 0 deletions packages/labs/context/src/legacy-decorators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './lib/decorators/consume.js';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment about keeping this in sync with decorators.ts?

and do we need a license header?

export * from './lib/decorators/provide.js';
68 changes: 68 additions & 0 deletions packages/labs/context/src/lib/std-decorators/consume.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/

import {ReactiveElement} from '@lit/reactive-element';
import {ContextConsumer} from '../controllers/context-consumer.js';
import {Context} from '../create-context.js';

/**
* A property decorator that adds a ContextConsumer controller to the component
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to get more specific with the decorator type? "A field and accessor decorator" maybe?

* which will try and retrieve a value for the property via the Context API.
*
* @param context A Context identifier value created via `createContext`
* @param subscribe An optional boolean which when true allows the value to be
* updated multiple times.
*
* @example
*
* ```ts
* import {consume} from '@lit-labs/context/std-decorators/consume.js';
* import {loggerContext, Logger} from 'community-protocols/logger';
*
* class MyElement {
* @consume({context: loggerContext})
* logger?: Logger;
*
* doThing() {
* this.logger?.log('thing was done');
* }
* }
* ```
* @category Decorator
*/
export function consume<Provided>({
context,
subscribe,
}: {
context: Context<unknown, Provided>;
subscribe?: boolean;
}) {
return <This extends ReactiveElement, Consuming>(
_target: unknown,
decoratorContext:
| ClassFieldDecoratorContext<This, Consuming>
| ClassAccessorDecoratorContext<This, Consuming>
): EnforceTypesMatch<Provided, Consuming, void> => {
decoratorContext.addInitializer(function (this: This) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool! I'm looking forward to getting rid of our own addInitializer()

new ContextConsumer(this, {
context,
callback: (value: Provided) => {
decoratorContext.access.set(this, value as unknown as Consuming);
},
subscribe,
});
});
return undefined as unknown as EnforceTypesMatch<Provided, Consuming, void>;
};
}

type EnforceTypesMatch<Provided, Consuming, Ok> = [Provided] extends [Consuming]
? Ok
: {
message: "the provided type isn't assignable to the consuming field";
provided: Provided;
consuming: Consuming;
};
100 changes: 100 additions & 0 deletions packages/labs/context/src/lib/std-decorators/provide.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/

import {ReactiveElement} from '@lit/reactive-element';
import {Context} from '../create-context.js';
import {ContextProvider} from '../controllers/context-provider.js';

/*
* IMPORTANT: For compatibility with tsickle and the Closure JS compiler, all
* property decorators (but not class decorators) in this file that have
* an @ExportDecoratedItems annotation must be defined as a regular function,
* not an arrow function.
*/

/**
* A property decorator that adds a ContextConsumer controller to the component
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* A property decorator that adds a ContextConsumer controller to the component
* A property decorator that adds a ContextProvider controller to the component

Not sure fi this needs to be done in the existing decorators too

* which will try and retrieve a value for the property via the Context API.
*
* @param context A Context identifier value created via `createContext`
* @param multiple An optional boolean which when true allows the value to be updated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this param

* multiple times.
*
* See: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

*
* @example
*
* ```ts
* import {consume} from '@lit-labs/context';
* import {loggerContext} from 'community-protocols/logger';
*
* class MyElement {
* @provide({context: loggerContext})
* logger;
*
* doThing() {
* this.logger.log('thing was done');
* }
* }
* ```
* @category Decorator
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we make a new category for standard decorators?

*/
export function provide<Expected>({
context: context,
}: {
context: Context<unknown, Expected>;
}) {
return <This extends ReactiveElement, Providing>(
target: ClassAccessorDecoratorTarget<This, Providing>,
decoratorContext: ClassAccessorDecoratorContext<This, Providing>
): EnforceTypesMatch<
Expected,
Providing,
ClassAccessorDecoratorResult<This, Providing>
> => {
const controllerMap = new WeakMap<
This,
ContextProvider<Context<unknown, Providing>>
>();
decoratorContext.addInitializer(function (this: This) {
controllerMap.set(
this,
new ContextProvider(
this,
// this cast is ok because we're already using the type system to
// ensure that Providing is assignable to Expected
{context: context as unknown as Context<unknown, Providing>}
)
);
});
const result: ClassAccessorDecoratorResult<This, Providing> = {
get(this: This) {
return target.get.call(this);
},
set(this: This, value: Providing) {
controllerMap.get(this)?.setValue(value);
return target.set.call(this, value);
},
init(this: This, value: Providing) {
controllerMap.get(this)?.setValue(value);
return value;
},
};
return result as unknown as EnforceTypesMatch<
Expected,
Providing,
ClassAccessorDecoratorResult<This, Providing>
>;
};
}

type EnforceTypesMatch<Expected, Providing, Ok> = [Providing] extends [Expected]
? Ok
: {
message: "the providing field isn't assignable to this context";
providing: Providing;
context: Expected;
};
2 changes: 2 additions & 0 deletions packages/labs/context/src/std-decorators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './lib/std-decorators/consume.js';
export * from './lib/std-decorators/provide.js';
Loading