Skip to content

Commit 54961cc

Browse files
johnjenkinsJohn Jenkins
andauthored
feat: v4.40 (#1568)
* chore: * chore: * chore: * chore: slotAssignment and dev sourceMaps --------- Co-authored-by: John Jenkins <john.jenkins@nanoporetech.com>
1 parent ab7b5bc commit 54961cc

File tree

108 files changed

+17009
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+17009
-11
lines changed

docs/components/component.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export class TodoList {
184184

185185
**Optional**
186186

187-
**Type: `boolean | { delegatesFocus: boolean }`**
187+
**Type: `boolean | { delegatesFocus?: boolean, slotAssignment?: 'manual' | 'named' }`**
188188

189189
**Default: `false`**
190190

@@ -201,6 +201,10 @@ When `delegatesFocus` is `true` and a non-focusable part of the component is cli
201201
- the first focusable part of the component is given focus
202202
- the component receives any available `focus` styling
203203

204+
When `slotAssignment` is set to `'manual'` or `'named'`, the component will have `slotAssignment` added to its shadow DOM.
205+
206+
`slotAssignment: 'manual'` enables [manual slot assignment](https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/slotAssignment) (otherwise known as [imperative slot assignment](https://github.com/WICG/webcomponents/blob/gh-pages/proposals/Imperative-Shadow-DOM-Distribution-API.md)) for the component.
207+
204208
If `shadow` is set to `false`, the component will not use native shadow DOM encapsulation.
205209

206210
This option cannot be set to enabled if `scoped` is enabled.

docs/components/reactive-data.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ When props or state change on a component, the [`render()` method](./templating-
1616
## The Watch Decorator (`@Watch()`)
1717

1818
`@Watch()` is a decorator that is applied to a method of a Stencil component.
19-
The decorator accepts a single argument, the name of a class member that is decorated with `@Prop()` or `@State()`, or
19+
The decorator's first required argument is the name of a class member that is decorated with `@Prop()` or `@State()`, or
2020
a host attribute. A method decorated with `@Watch()` will automatically run when its associated class member or attribute changes.
2121

2222
```tsx
@@ -52,22 +52,29 @@ export class LoadingIndicator {
5252
}
5353

5454
@Watch('activated')
55-
@Watch('busy')
55+
@Watch('busy', {immediate: true})
5656
watchMultiple(newValue: boolean, oldValue: boolean, propName:string) {
5757
console.log(`The new value of ${propName} is: `, newValue);
5858
}
5959
}
6060
```
6161

62-
In the example above, there are two `@Watch()` decorators.
63-
One decorates `watchPropHandler`, which will fire when the class member `activated` changes.
64-
The other decorates `watchStateHandler`, which will fire when the class member `busy` changes.
62+
In the example above, there are four `@Watch()` decorators:
63+
- The first decorates `watchPropHandler`, which will fire when the class member `activated` changes.
64+
- The second decorates `watchStateHandler`, which will fire when the class member `busy` changes.
65+
- The third and fourth decorators both decorate `watchMultiple`, which will fire when either `activated` or `busy` change.
66+
67+
Passing `{immediate: true}` as the second argument to `@Watch()` causes the decorated
68+
method to fire when the component initially loads, in addition to when the watched member changes.
6569

6670
When fired, the decorated method will receive the old and new values of the prop/state.
6771
This is useful for validation or the handling of side effects.
6872

6973
:::info
70-
The `@Watch()` decorator does not fire when a component initially loads.
74+
By default, the `@Watch()` decorator does not fire when a component initially loads.
75+
Use `@Watch('propName', {immediate: true})` to have the decorated method fire when the component first loads.
76+
`immediate` watchers will be invoked before the component's first render, so be careful when trying to access DOM elements
77+
that may not yet be available.
7178
:::
7279

7380
### Watching Native HTML Attributes

docs/config/01-overview.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,14 @@ Will generate the following comment:
406406

407407
## sourceMap
408408

409-
*default: `true`*
409+
*default: `'dev'`*
410410

411-
When omitted or set to `true`, sourcemaps will be generated for a project.
412-
When set to `false`, sourcemaps will not be generated.
411+
- Set to `true` to always generate source maps,
412+
- Set to `false` to never generate source maps
413+
- Set to `'dev'` to only generate source maps during development (`--dev`) builds.
413414

414415
```tsx
415-
sourceMap: true | false
416+
sourceMap: true | false | 'dev'
416417
```
417418

418419
Sourcemaps create a translation between Stencil components that are written in TypeScript/JSX and the resulting
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: Build Constants
3+
description: Stencil has a number of add-ons that you can use with the build process.
4+
slug: /build-variables
5+
---
6+
7+
# Build Constants
8+
9+
Build Constants in Stencil allow you to run specific code only when Stencil is running in development mode. This code is stripped from your bundles when doing a production build, therefore keeping your bundles as small as possible.
10+
11+
### Using Build Constants
12+
13+
Lets dive in and look at an example of how to use our build constants:
14+
15+
```tsx
16+
import { Component, Build } from '@stencil/core';
17+
18+
@Component({
19+
tag: 'stencil-app',
20+
styleUrl: 'stencil-app.scss'
21+
})
22+
export class StencilApp {
23+
24+
componentDidLoad() {
25+
if (Build.isDev) {
26+
console.log('im in dev mode');
27+
} else {
28+
console.log('im running in production');
29+
}
30+
31+
if (Build.isBrowser) {
32+
console.log('im in the browser');
33+
} else {
34+
console.log('im in prerendering (server)');
35+
}
36+
}
37+
}
38+
```
39+
40+
As you can see from this example, we just need to import `Build` from `@stencil/core` and then we can use the `isDev` constant to detect when we are running in dev mode or production mode.
41+
42+
### Use Cases
43+
44+
Some use cases we have come up with are:
45+
46+
- Diagnostics code that runs in dev to make sure logic is working like you would expect
47+
- `console.log()`'s that may be useful for debugging in dev mode but that you don't want to ship
48+
- Disabling auth checks when in dev mode
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "Components",
3+
"position": 2
4+
}

0 commit comments

Comments
 (0)