Conversation
| export type { AnimationSettings } from '../src/core/animations/CoreAnimation.js'; | ||
| export type { TimingFunction } from '../src/core/utils.js'; | ||
| export type { Inspector } from '../src/main-api/Inspector.js'; | ||
| export type { CoreNodeRenderState } from '../src/core/CoreNode.js'; |
There was a problem hiding this comment.
I'd also like to report something here.
Is it intended for consumers of lightningjs/renderer to be able to do:
import { CoreNodeRenderState } from '@lightningjs/renderer';
if (renderState === CoreNodeRenderState.InViewport) { ... }?
Because if so, then this isn't working. All enums are being exported as export declare enum X. In order to preserve enums for consumers, preserveConstEnums must be used.
|
@guilhermesimoes I think you aren't approaching that correctly - to create nodes you should be go through the
Both the official Blits and unofficial SolidJS frameworks use this API, and in both cases they don't directly extend those objects, which is potentially a departure from the Lightning 2 approach where you can extend the base Element type. |
|
The entire Peacock codebase is written in a class based approach, more or less like this: import { Component, Element } from '@lightningjs/core';
export class SomePage extends Component {
private title: TextElement;
constructor(stage: Stage) {
super(stage);
const title = (this.title = new Element(stage));
title.y = SOME_PAGE_TITLE_Y;
title.x = HORIZONTAL_SAFE_ZONE;
title.text = 'Hello World';
}
}As you can imagine, migrating over 300 components is not an easy task. We could create our own import {
type Stage,
type CoreNode // note, we can't even do this import
} from '@lightningjs/renderer';
export class Element {
private node: CoreNode;
constructor(stage: Stage, props = {} as CoreNodeProps) {
this.node = stage.createNode(props);
}
set x(x) {
this.node.x = x;
}
get x() {
return this.node.x;
}
// etc ...
}But this approach has several disadvantages:
As such, we believe a better approach for a progressive migration from Lightning 2 to 3 is like so: import {
type Stage,
type CoreNodeProps, // we also need this import, which doesn't work
CoreNode
} from '@lightningjs/renderer';
export class Element extends CoreNode {
constructor(stage: Stage, props = {} as CoreNodeProps) {
super(stage, stage.resolveNodeDefaults(props));
}
}This approach:
We understand this may not fit in the Lightning team's vision of a declarative approach such as SolidJS or Blits, which at build time transform templates into nested calls to |
Add type exports
TextRenderer,CoreNodePropsandCoreTextNodeProps.Also export
CoreNodeandCoreTextNodesince we can't usestage.createNode()orstage.createTextNode().Peacock has been using Lightning v2's
Elementfor several years now, so all our components extend that class. In order to migrate to Lightning v3, we need access to the new building blocks,CoreNodeandCoreTextNode, so that our components can extend those.