@lightningjs/blits 0.6.13 → 0.7.1

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.
package/src/lib/hooks.js CHANGED
@@ -19,8 +19,8 @@ import symbols from './symbols.js'
19
19
 
20
20
  const cbs = {}
21
21
 
22
- export const emit = (hook, name, scope) => {
23
- cbs[name] && cbs[name][hook] && cbs[name][hook].apply(scope)
22
+ export const emit = (hook, name, scope, data = []) => {
23
+ cbs[name] && cbs[name][hook] && cbs[name][hook].apply(scope, data)
24
24
  }
25
25
 
26
26
  export const privateEmit = (hook, name, scope) => {
@@ -0,0 +1,42 @@
1
+ /*
2
+ * Copyright 2024 Comcast Cable Communications Management, LLC
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ *
15
+ * SPDX-License-Identifier: Apache-2.0
16
+ */
17
+
18
+ import { Log } from './log.js'
19
+ import { emit, privateEmit } from './hooks.js'
20
+
21
+ const states = ['init', 'ready', 'focus', 'unfocus', 'destroy']
22
+
23
+ export default {
24
+ previous: null,
25
+ current: null,
26
+ get state() {
27
+ return this.current
28
+ },
29
+ set state(v) {
30
+ if (states.indexOf(v) > -1 && v !== this.current) {
31
+ Log.debug(
32
+ `Setting lifecycle state from ${this.current} to ${v} for ${this.component.componentId}`
33
+ )
34
+ this.previous = this.current
35
+ this.current = v
36
+ // emit 'private' hook
37
+ privateEmit(v, this.component.name, this.component)
38
+ // emit 'public' hook
39
+ emit(v, this.component.name, this.component)
40
+ }
41
+ },
42
+ }
@@ -57,9 +57,14 @@ const reactiveProxy = (target) => {
57
57
  set(target, key, value, receiver) {
58
58
  const oldValue = target[key]
59
59
 
60
- const result = Reflect.set(target, key, value, receiver)
60
+ let result
61
+ if (typeof value === 'object' && Array.isArray(value) && proxyMap.get(target[key])) {
62
+ result = target[key].splice(0, target[key].length, ...value)
63
+ } else {
64
+ result = Reflect.set(target, key, value, receiver)
65
+ }
61
66
 
62
- if (typeof result === 'object') {
67
+ if (typeof value === 'object') {
63
68
  reactiveProxy(target[key])
64
69
  }
65
70
 
@@ -104,6 +109,7 @@ const reactiveDefineProperty = (target) => {
104
109
  return internalValue
105
110
  },
106
111
  set(newValue) {
112
+ // todo: support assigning array (as we do with proxies)
107
113
  let oldValue = internalValue
108
114
  if (oldValue !== newValue) {
109
115
  internalValue = newValue
@@ -35,8 +35,14 @@ const shaderAlias = {
35
35
  rounded: 'radius',
36
36
  }
37
37
 
38
- export default (component) => {
38
+ export default (component, name) => {
39
39
  Object.defineProperties(component.prototype, {
40
+ name: {
41
+ value: name,
42
+ writable: false,
43
+ enumerable: true,
44
+ configurable: false,
45
+ },
40
46
  focus: {
41
47
  value: function (e) {
42
48
  Focus.set(this, e)
@@ -242,11 +248,8 @@ const deleteChildren = function (children) {
242
248
  if (!children[i]) return
243
249
  if (Array.isArray(children[i])) {
244
250
  deleteChildren(children[i])
245
- } else if (children[i].delete) {
246
- children[i].delete()
247
251
  } else if (children[i].destroy) {
248
252
  children[i].destroy()
249
- children[i] = null
250
253
  }
251
254
  children[i] = null
252
255
  }
@@ -28,7 +28,9 @@ export let navigating = false
28
28
 
29
29
  const cacheMap = new WeakMap()
30
30
  const history = []
31
+
31
32
  let overrideOptions = {}
33
+ let navigationData = {}
32
34
  let navigatingBack = false
33
35
  let previousFocus
34
36
 
@@ -133,7 +135,8 @@ export const navigate = async function () {
133
135
  holder.set('w', '100%')
134
136
  holder.set('h', '100%')
135
137
  // merge props with potential route params to be injected into the component instance
136
- const props = { ...this[symbols.props], ...route.params }
138
+ const props = { ...this[symbols.props], ...route.params, ...navigationData }
139
+
137
140
  view = await route.component({ props }, holder, this)
138
141
  if (view[Symbol.toStringTag] === 'Module') {
139
142
  if (view.default && typeof view.default === 'function') {
@@ -233,7 +236,7 @@ const removeView = async (route, view, transition) => {
233
236
  cacheMap.set(route, { view: view, focus: previousFocus })
234
237
  } else {
235
238
  // remove and cleanup
236
- for (let i = 0; i < view[symbols.children].length - 1; i++) {
239
+ for (let i = 0; i < view[symbols.children].length; i++) {
237
240
  if (view[symbols.children][i] && view[symbols.children][i].destroy) {
238
241
  view[symbols.children][i].destroy()
239
242
  view[symbols.children][i] = null
@@ -250,7 +253,8 @@ const setOrAnimate = (node, transition, shouldAnimate = true) => {
250
253
  : node.set(transition.prop, transition.value)
251
254
  }
252
255
 
253
- export const to = (location, options = {}) => {
256
+ export const to = (location, data = {}, options = {}) => {
257
+ navigationData = data
254
258
  overrideOptions = options
255
259
  window.location.hash = `#${location}`
256
260
  }