@lightningjs/blits 1.30.1 → 1.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/package.json +4 -3
  3. package/src/router/router.js +2 -0
  4. package/vite/preCompiler.js +6 -1
  5. package/.editorconfig +0 -7
  6. package/.eslintignore +0 -1
  7. package/.eslintrc.cjs +0 -65
  8. package/.github/workflows/comment-lint-results.yml +0 -125
  9. package/.github/workflows/comment-test-results.yml +0 -109
  10. package/.github/workflows/deploy-docs.yml +0 -27
  11. package/.github/workflows/run-blits-tests.yml +0 -142
  12. package/.github/workflows/run-lint.yml +0 -128
  13. package/.husky/pre-commit +0 -1
  14. package/.husky/pre-push +0 -1
  15. package/.vscode/extensions.json +0 -7
  16. package/.vscode/settings.json +0 -9
  17. package/banner.png +0 -0
  18. package/docs/.nojekyll +0 -0
  19. package/docs/README.md +0 -19
  20. package/docs/_sidebar.md +0 -37
  21. package/docs/built-in/directives.md +0 -50
  22. package/docs/built-in/for-loop.md +0 -204
  23. package/docs/built-in/layout.md +0 -168
  24. package/docs/components/component_state.md +0 -90
  25. package/docs/components/computed_properties.md +0 -45
  26. package/docs/components/lifecycle_events.md +0 -42
  27. package/docs/components/methods.md +0 -45
  28. package/docs/components/props.md +0 -56
  29. package/docs/components/user_input.md +0 -186
  30. package/docs/components/utility_methods.md +0 -320
  31. package/docs/components/watchers.md +0 -34
  32. package/docs/essentials/application_root.md +0 -19
  33. package/docs/essentials/components.md +0 -68
  34. package/docs/essentials/displaying_images.md +0 -67
  35. package/docs/essentials/displaying_text.md +0 -135
  36. package/docs/essentials/element_attributes.md +0 -195
  37. package/docs/essentials/settings.md +0 -117
  38. package/docs/essentials/template_syntax.md +0 -83
  39. package/docs/getting_started/file_structure.md +0 -58
  40. package/docs/getting_started/getting_started.md +0 -45
  41. package/docs/getting_started/intro.md +0 -20
  42. package/docs/index.html +0 -47
  43. package/docs/performance/lazy-loading.md +0 -161
  44. package/docs/plugins/global_app_state.md +0 -98
  45. package/docs/plugins/language.md +0 -172
  46. package/docs/plugins/text-to-speech-announcer.md +0 -120
  47. package/docs/plugins/theme.md +0 -176
  48. package/docs/router/basics.md +0 -175
  49. package/docs/router/hooks.md +0 -70
  50. package/docs/router/transitions.md +0 -146
  51. package/docs/sidebar.json +0 -171
  52. package/docs/transitions_animations/transitions.md +0 -150
  53. package/jsconfig.json +0 -12
  54. package/src/component/setup/props.test.js +0 -238
  55. package/src/component.test.js +0 -388
  56. package/src/components/Circle.orig.js +0 -31
  57. package/src/components/FPScounter.orig.js +0 -121
  58. package/src/components/RouterView.orig.js +0 -54
  59. package/src/components/Sprite.orig.js +0 -58
  60. package/src/components/index.orig.js +0 -28
  61. package/src/engines/L3/element.test.js +0 -579
  62. package/src/helpers/deepEqualArray.test.js +0 -127
  63. package/src/lib/codegenerator/generator.test.js +0 -3801
  64. package/src/lib/colors/colors.test.js +0 -290
  65. package/src/lib/componentId.test.js +0 -84
  66. package/src/lib/eventListeners.test.js +0 -236
  67. package/src/lib/reactivity/effect.test.js +0 -35
  68. package/src/lib/reactivity/reactive.test.js +0 -27
  69. package/src/lib/templateparser/parser.test.js +0 -1411
  70. package/src/router/router.test.js +0 -473
@@ -1,83 +0,0 @@
1
- # Template syntax
2
-
3
- Blits uses an easy-to-read _XML-style_ template syntax. The syntax is inspired by frameworks like VueJS, so if you are familiar with Vue, you will probably recognize certain concepts.
4
-
5
- The `template` key in the _Component configuration object_ is used to specify a string with this XML-like template structure. Templates can often span multiple lines. In those cases, it's advisable to use `template literals` (enclosed by backticks).
6
-
7
- Similar to HTML, you can use arguments and nested tags. Self-closing tags and HTML-style comments are also supported in Blits templates.
8
-
9
- The default tag that can be used in templates is the `<Element>` tag. The Element tag corresponds to a node in the Lightning 3 renderer.
10
-
11
- For each element, there is a set of predefined render properties, such as `x`, `y`, `w`, `color` that define how the element looks and where it is positioned. Detailed information on all the attributes supported by the `<Element>` tag can be found [here](./element_attributes.md).
12
-
13
- Now let's consider the following template example:
14
-
15
- ```xml
16
- <Element x="20" y="20">
17
- <Element w="100" h="100" x="360" color="#0891b2" />
18
- <Element w="$width" h="$height" color="$color" />
19
- <Element :w="$changingWidth" :h="Math.floor($height / 5)" :color="$highlight" />
20
- </Element>
21
- ```
22
-
23
- ## Hardcoded arguments
24
-
25
- In the template above, you'll observe certain arguments with hardcoded values (i.e. `w="100"` and `color="#0891b2"`).
26
- You can use hardcoded arguments to configure the parts of your template that you know will never change.
27
-
28
- ## Dynamic arguments
29
-
30
- Additionally, some arguments contain a value prefixed with a dollar sign (`$`). These are so called _dynamic_ arguments.
31
-
32
- The `$`-sign used in a template refers to a (state) variable on the Component. And when the template renders, it automatically populates
33
- these arguments with dynamic values based on the initial state of your Component.
34
-
35
- It's important to realize that dynamic arguments are only set _once_. Changing a value used in a dynamic argument, won't be reflected
36
- on screen. For that you will need to use _reactive_ arguments.
37
-
38
- ## Reactive arguments
39
-
40
- If you look at the template example above you'll notice that certain arguments are prefixed with a colon sign (`:`). Prefixing an argument
41
- with a colon makes it not only dynamic but also _reactive_.
42
-
43
- Reactive arguments are set with the initial state value when your component first renders, exactly as a dynamic argument does.
44
-
45
- The difference is that a _re-render_ of (a portion of) the template will be triggered whenever the referenced value in your Component's internal state changes.
46
-
47
- This concept of _reactive data binding_ eliminates the need for manual template patching and allows for a declarative way of programming.
48
-
49
- Reactive arguments also support _interpolation_. This enables the use of simple JavaScript instructions, such as ternary conditions or basic String and Math manipulations, right inside your template arguments.
50
-
51
- For more complex logic, it's recommended to abstract this into a [Component method](../components/methods.md) or a [Computed property](../components/computed_properties.md).
52
-
53
- # Abstracting template portions to custom components
54
-
55
- As your template grows in complexity, you may want to organize your codebase with custom components, abstracting a complex template into smaller, reusable pieces.
56
-
57
- When you've abstracted a portion of a template into a separate component, a _Menu_ component for example, you'll first need to `import` the file that contains the Menu component.
58
-
59
- Next, you have to _register_ the imported custom component. The `components`-key in the _configuration object_ is used for this.
60
-
61
- The `components` key is an _object literal_, where the value is the reference to the custom Blits component and the key will correspond with the _tag_ that can be used in the template to insert the component.
62
-
63
- Once this is done, the tag (`<Menu>` for example) is available for use in your component's template. You can use the component tag as many times as you want. For each tag, a new Component instance will be created.
64
-
65
- The example below shows how to use a custom `Menu` and `Button` (aliased to `MyButton`) component inside a template.
66
-
67
- ```js
68
- import Menu from './components/menu.js'
69
- import Button from './components/button.js'
70
-
71
- export default Blits.Component('MyComponent', {
72
- components: {
73
- Menu, // makes <Menu /> available for use in the template
74
- MyButton: Button, // makes Button available as <MyButton /> in the template
75
- },
76
- template: `
77
- <Element>
78
- <Menu />
79
- <MyButton />
80
- </Element>
81
- `
82
- })
83
- ```
@@ -1,58 +0,0 @@
1
- # File structure
2
-
3
- Once you have created a new Blits App using the boilerplate described in the [Getting started](getting_started.md), you should have a project with all the basics you need.
4
-
5
- Let's review the basic file structure, and take a closer look at the important ones.
6
-
7
- ## package.json
8
-
9
- In the root of your newly created app, you will obviously find a `package.json` with all the necessary (dev) dependencies.
10
-
11
- In order to build a Blits based Lightning 3 app, all you need is `@lightningjs/blits` as a dependency. Blits will take care of hooking up the Lightning 3 renderer for you behind the scenes.
12
-
13
- Feel free to install and import any custom library that your App may need. But always be mindful of the size and impact an external dependency may have - especially when developing for low powered devices (as is often the case with Lightning apps).
14
-
15
- ## index.html
16
-
17
- You will also find an `index.html` at the root of your project. This is where the browser will be pointed to, in order to launch your Blits App.
18
-
19
- If you inspect the source you will see some minimal HTML. The essential parts of the HTML are the `<div>` where the canvas will be injected into, and the `<script>`-tag that points to the `index.js` of the App.
20
-
21
- ## public
22
-
23
- There is also a `public` folder in your project. This folder is used for storing public assets, such as App images and fonts.
24
-
25
- During development, your assets are loaded directly from this folder. And if you run a production build, the entire `public` folder is copied over to the distributable version.
26
-
27
- ## src
28
-
29
- The `src`-folder is where all your custom App code lives.
30
-
31
- ### index.js
32
-
33
- `src/index.js` is the entry point of your App. This file imports the Blits `Launch`-method which initializes the App.
34
-
35
- The `Blits.Launch()`-method accepts 3 parameters:
36
-
37
- 1) `app` - the root application component
38
- 2) `target` - the HTML target to append the canvas to. This can either be an `id` of an HTML element in `index.html`, or you can pass a reference to HTML element itself
39
- 3) `settings` - an `object` with settings
40
-
41
- ### App.js
42
-
43
- `src/App.js` is the default file where the root application component lives. It's expected to export a `Blits.Application()`-instance, which is the base component of your App.
44
-
45
- ## components and pages folder
46
-
47
- The rest of your App can be built out using components. You are free to organize your components as you wish, but we recommend using a separate file for each component and placing them in the `src/components`-folder.
48
-
49
- The convention is to start the component file name with a capital letter, matching the name of the component (e.g. `src/components/Loader.js` or `src/components/MenuItem.js`).
50
-
51
- Feel free to further organize and possibly nest your Component files to your own preferences.
52
-
53
- Pages in your App are technically just Blits components as well. But to keep things clear, we often place them in a separate `pages`-folder alongside the `components`-folder (e.g. `src/pages/Home.js` and `src/pages/Details.js`)
54
-
55
- ### Custom code
56
-
57
- If your App needs libraries for specific (business) logic that can be shared across components (such as API calls) you can place them anywhere in your `src` folder. For example in a folder named `src/lib` or `src/api`.
58
-
@@ -1,45 +0,0 @@
1
- # Getting Started
2
-
3
- To get started with Blits, follow these simple steps to set up your development environment and create your first Lightning 3 App.
4
-
5
- ## Installation
6
-
7
- 1. Open your terminal or command prompt.
8
-
9
- 2. Run the following command to start a new Blits Lightning 3 App project:
10
-
11
- ```bash
12
- npm create @lightningjs/app
13
- ```
14
-
15
- You will be guided through a short series of questions to generate a new project with all the boilerplate code you need to start building your own Lightning 3 App.
16
-
17
- 3. Navigate to the newly created project directory and install the project dependencies:
18
-
19
- ```bash
20
- cd my_blits_app
21
- npm install
22
- ```
23
-
24
- ## Running Your App
25
-
26
- 4. After installing the dependencies, you can start your development server by running:
27
-
28
- ```bash
29
- npm run dev
30
- ```
31
-
32
- This command will create an application bundle and launch a development server using Vite.
33
-
34
- Once the server is up and running, open your web browser and navigate to the URL displayed in the console. Congratulations! You now have your brand new Blits Lightning 3 App up and running.
35
-
36
- ## Coding environment
37
-
38
- You can use any code editor of your preference to further develop your Blits App.
39
-
40
- We recommend using VS code, since we have a dedicated [VS code extension for Blits](https://marketplace.visualstudio.com/items?itemName=LightningJS.lightning-blits) that provides better syntax highlighting, code completion, error
41
- checking, and other features to make working with Blits easier.
42
-
43
- ## Next steps
44
-
45
- You are now ready to dive into the world of App development using Blits. In the following sections, we will explore the core concepts and guide you through building your TV applications step by step.
@@ -1,20 +0,0 @@
1
- # Blits - Lightning 3 App Development Framework
2
-
3
- With Blits, the App Development Framework for Lightning 3, it becomes a breeze to build great Lightning 3 applications.
4
-
5
- Blits is built on top of the Lightning 3 Renderer and aims to provide a **great developer experience**, making it fun and easy to build your apps!
6
-
7
- Built from the ground up by the LightningJS team, we're offering a **Complete App framework**, full of features to speed up development, while keeping it **lightweight** with a focus on **performance**.
8
-
9
- The Blits framework uses a **readable** XML-style template syntax and comes with built-in reactivity.
10
-
11
- ## Why Blits?
12
-
13
- You may be wondering where the name Blits comes from.
14
-
15
- Firstly, it's short, memorable and just has a nice ring to it.
16
-
17
- "Blits" is a Dutch word (a significant portion of the Lightning Open Source team is based in the Netherlands). It means _flashy_ and it's often used for things that are _great_ or _cool_.
18
-
19
- Finally, it's a nerdy reference to the computer term "Bit Blits" commonly used in graphics processing, for rapidly moving a block of data into memory - quite similar to what Lightning is doing 🙂
20
-
package/docs/index.html DELETED
@@ -1,47 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>Blits Lightning App Development Framework</title>
6
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
7
- <meta name="description" content="Description">
8
- <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
9
- <!--link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple.css"-->
10
- <link
11
- rel="stylesheet"
12
- href="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/style.min.css"
13
- title="docsify-darklight-theme"
14
- type="text/css"
15
- />
16
- </head>
17
- <body>
18
- <div id="app"></div>
19
- <script>
20
- window.$docsify = {
21
- name: 'Blits <br />L3 App Development Framework',
22
- repo: 'https://github.com/lightning-js/blits/',
23
- loadSidebar: true,
24
- relativePath: true,
25
- auto2top: true,
26
- search: {
27
- maxAge: 24*60*60*1000, // one day
28
- paths: 'auto',
29
- placeholder: 'Type to search',
30
- noData: 'No Results!',
31
- depth: 6,
32
- },
33
- darklightTheme: {
34
- defaultTheme : 'dark',
35
- }
36
- }
37
-
38
- </script>
39
- <script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
40
- <script src="https://cdn.jsdelivr.net/npm/docsify-themeable@0"></script>
41
- <script
42
- src="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/index.min.js"
43
- type="text/javascript">
44
- </script>
45
- <script src="//unpkg.com/docsify/lib/plugins/search.js"></script>
46
- </body>
47
- </html>
@@ -1,161 +0,0 @@
1
- # Lazy Loading with the :range Parameter
2
-
3
- The for-loop in Blits comes with a [`:range` parameter](../built-in/for-loop.html#using-the-range-attribute) that allows you to render only a portion of an array rather than all the items.
4
-
5
- This `:range` parameter can also be used to easily implement an efficient form of _lazy loading_. Lazy loading is a crucial concept for performance in TV applications where rails can contain hundreds of items, but only a small subset is visible at any time.
6
-
7
- ## Basic range implementation
8
-
9
- For the basic syntax of the `:range` attribute, we typically set dynamic `from` and `to` values, which define the subset of items to display.
10
-
11
- ```js
12
- <Tile :for="(item, index) in $items" :range="{from: $from, to: $to}" />
13
- ```
14
-
15
- A full example of a Rail component with a range would look something like this:
16
-
17
- ```js
18
- export default Blits.Component('RangedRail', {
19
- template: `
20
- <Element :x.transition="0 - $focused * 300">
21
- <Tile
22
- :for="(item, index) in $items"
23
- :range="{from: $range, to: $range + 7}"
24
- :key="$item.id"
25
- :focused="$focused"
26
- w="300"
27
- h="200"
28
- :x="$index * 320"
29
- />
30
- </Element>
31
- `,
32
- state() {
33
- return {
34
- range: 0,
35
- focused: 0,
36
- items: [] // Array of 100+ items
37
- }
38
- },
39
- input: {
40
- right() {
41
- this.focus = Math.min(this.focus + 1, items.length)
42
- this.range++
43
- },
44
- left() {
45
- this.focus = Math.max(this.focus - 1, 0)
46
- this.range--
47
- }
48
- }
49
- })
50
- ```
51
-
52
- Benefits of this approach are:
53
-
54
- - **Selective Rendering**: Only items within the specified range are actually created as elements
55
- - **Performance Optimization**: Reduces memory usage and improves rendering performance
56
- - **Dynamic Range Updates**: The range can be computed based on user interaction and scroll position
57
-
58
- A downside of this approach is that, as we scroll we are also **destroying** components that are out of range. And we may need those
59
- same items when we scroll back (and thus recreate them). On top of that, destroying Components and Elements also comes at a cost.
60
-
61
- ## Lazy loading with the range attribute
62
-
63
- We can solve the problem of destroying Components that we may want to use again by slightly changing the logic of the Rail component.
64
-
65
- 1) We set `from: 0`, to ensure we always start from the first item (and _keep_ the first items)
66
- 2) We use `to: $range + 7` to render up to the current position plus a lookahead buffer
67
- 3) The `$range` value tracks how far the user has navigated through the rail, but it doesn't decrement when navigating back
68
-
69
- With these changes a full example of a LazyRail component would look something like this:
70
-
71
- ```js
72
- export default Blits.Component('LazyRail', {
73
- template: `
74
- <Element :x.transition="0 - $focused * 300">
75
- <Tile
76
- :for="(item, index) in $items"
77
- :range="{from: 0, to: $range + 7}"
78
- :key="$item.id"
79
- w="300"
80
- h="200"
81
- :x="$index * 320"
82
- />
83
- </Element>
84
- `,
85
- state() {
86
- return {
87
- range: 0,
88
- items: [] // Array of 100+ items
89
- }
90
- },
91
- input: {
92
- right() {
93
- this.focus = Math.min(this.focus + 1, items.length)
94
- // push the range update to the next tick to spread out the work
95
- // and ease the CPU a bit
96
- this.$setTimeout(() => this.range = this.focus)
97
-
98
- },
99
- left() {
100
- this.focus = Math.max(this.focus - 1, 0)
101
- // we don't decrement the range when scrolling back to keep components alive
102
- // this.range--
103
- }
104
- }
105
- })
106
- ```
107
-
108
- ## Performance Benefits
109
-
110
- Properly applying the range attribute provides **Memory Efficiency**:
111
-
112
- - Instead of creating 100+ elements, only ~8-15 are active
113
- - Reduces GPU memory usage on constrained TV hardware
114
- - Lower overall memory footprint
115
-
116
- It also is beneficial for **Faster Rendering**
117
-
118
- - Initial page load only renders visible items
119
- - Scroll performance improves as fewer elements need updates
120
- - Reduced layout calculations
121
-
122
-
123
- It **optimizes bandwidth**
124
-
125
- - Images and assets only load for rendered items
126
- - Reduces network requests on page load
127
- - Progressive content loading
128
-
129
-
130
- ### Alpha Transitions
131
-
132
- For a smoother experience you consider applying an alpha transition, that fades out items at the end of the rang.e
133
-
134
- ```js
135
- :alpha.transition="$index <= $range ? 1 : ($index <= $range + 3 ? 0.8 : 0.6)"
136
- ```
137
-
138
- This creates a dimming effect for previously viewed items while maintaining full opacity for the current and upcoming items.
139
-
140
- ## Best Practices
141
-
142
- ### Buffer Size
143
-
144
- Use a buffer of 5-10 items ahead of current position:
145
-
146
- ```js
147
- // Conservative buffer for low-end devices
148
- :range="{from: $currentIndex - 1, to: $currentIndex + 6}"
149
-
150
- // Larger buffer for smoother experience
151
- :range="{from: $currentIndex - 2, to: $currentIndex + 10}"
152
- ```
153
-
154
- ## Performance Impact
155
-
156
- On typical TV hardware:
157
-
158
- - **Memory Usage**: 70-80% reduction compared to full rendering
159
- - **Initial Load Time**: 3-5x faster page initialization
160
- - **Scroll Performance**: Consistent fps maintained vs potential frame drops
161
- - **Network Requests**: Reduced by 80-90% on initial load
@@ -1,98 +0,0 @@
1
- # Global App State plugin
2
-
3
- Each Blits Component has its own, internal component state that is reactive and can automatically trigger updates in the template upon changes. The internal state is fully encapsulated, which ensures predictable component state and promotes a pattern of clear separation of concerns.
4
-
5
- But a Component usually doesn't live on its own, instead it's part of a bigger App. And there may arise a need for components to exchange data - intercomponent communication in other words.
6
-
7
- Blits offers the option to _emit_ and _listen_ to events, as explained in the section on Blits [utility methods](../components/utility_methods.md). For simple use cases, this is a convenient method to pass data along. But when used extensively, it may be easy to lose track of data flows.
8
-
9
- For more advanced cases, Blits offers an optional Global App State plugin that will act as a global state store that all components have direct access to. It's a simple implementation, focused on providing a _performant_ and _easy to use_ solution for global state. It's not a full flux / redux style state management solution, as we know from experience that these solutions (while very useful and cool), may lead to performance issues on low-end devices.
10
-
11
- ## Registering the plugin
12
-
13
- The Global App state plugin is provided in the core Blits package, but as it's an _optional_ plugin it first needs to be registered.
14
-
15
- The plugin can be imported from Blits and registered in the App's `index.js`, as demonstrated in the example below.
16
-
17
- Make sure to place the `Blits.Plugin()` method _before_ calling the `Blits.Launch()` method.
18
-
19
- ```js
20
- // index.js
21
-
22
- import Blits from '@lightningjs/blits'
23
- // import the app state plugin
24
- import { appState } from '@lightningjs/blits/plugins'
25
-
26
- import App from './App.js'
27
-
28
- // Use the Blits App State plugin
29
- Blits.Plugin(appState, {
30
- loggedIn: false,
31
- user: {
32
- id: null,
33
- name: '',
34
- lastname: ''
35
- },
36
- languages: ['en', 'nl', 'pt', 'es'],
37
- })
38
-
39
-
40
- Blits.Launch(App, 'app', {
41
- // launch settings
42
- })
43
- ```
44
-
45
- ### State object
46
-
47
- When registering the Global App State plugin, you pass it a state object as the second argument. This is a plain object literal that will be converted into a _reactive_ object, and is used to keep track of the global state variables.
48
-
49
- The newly created Global App state works exactly the same as an internal Component state. You can read values and you can directly change values. And when you do change a value, it automatically triggers reactive updates. Either via reactive attributes in the template, or in the form of watchers / computed values in the Component logic.
50
-
51
- ### Using global app state in a Component
52
-
53
- Any variable in the Global App state can be used directly in the template, much like a local Component state. Changing values in the global app state also works exactly the same as updating the internal component state.
54
-
55
- ```js
56
- Blits.Component('MyComponent', {
57
- template: `
58
- <Element>
59
- <Text :content="$$appState.loggedIn ? $$appState.user.name : 'Not logged in'" />
60
- </Element>
61
- `,
62
- input: {
63
- enter() {
64
- this.$appState.user.name = 'John'
65
- this.$appState.loggedIn = true
66
- }
67
- },
68
- })
69
- ```
70
-
71
- Note that in the template definition, 2 consecutive dollars signs are used (`$$appState`). The first `$`-sign is used
72
- to refer to the Component scope, as with any other state variable or computed property referenced in the template.
73
-
74
- The second `$`-sign is needed, since the appState plugin itself is prefixed with a dollar sign, to prevent accidental naming collisions.
75
-
76
- In order to read or update variables on the global app state inside the component logic, you can access the entire state via `this.$appState`.
77
-
78
- ### Watching global state
79
-
80
- Similar to component state, you can watch for changes in the global state as well. You can refer to global state variables using _dot-notation_ in the watcher function name, and _prefixing_ it with `$appState`. This means that you need to define your watcher as a `String`, matching one of the examples below, depending on your style preference.
81
-
82
- ```js
83
- Blits.Component('MyComponent', {
84
- template: `
85
- <Element>
86
- <Text :content="$$appState.loggedIn ? $$appState.user.name : 'Not logged in'" />
87
- </Element>
88
- `,
89
- watch: {
90
- '$appState.fooBar'(v, old) {
91
- console.log(`$appState.fooBar changed from ${old} to ${v}`)
92
- },
93
- '$appState.my.nested.data': function(v, old) {
94
- console.log(`My nested App state data changed!`)
95
- }
96
- },
97
- })
98
- ```