Migrate to V2
As mentioned in the v2 release blog post, Angular Three v2 is a major release with a substantial change in the migration strategy. It aims to address the limitations of the previous version, resulting in numerous breaking changes. Some of these changes are subtle and may not be immediately apparent.
While it is mentioned that migration path cannot be provided in details, I will try my best to provide a non-exhaustive overview of the changes and how to migrate.
Custom Renderer
While many have noticed the custom renderer usage from the previous version of the documentation, it has been brought to my attention that some folks are still using angular-three
before the custom renderer.
Here’s a quick summary:
- Use
NgtCanvas
withsceneGraph
input instead of putting your scene graph as content child ofngt-canvas
sceneGraph
is a reference to aComponent
that renders your entire scene graph.
CUSTOM_ELEMENTS_SCHEMA
is required. Please refer to the Custom Renderer documentation for more information.- All
ngt-*
elements do not have an importable symbol (they’re notDirective
norComponent
).
Scene Graph Inputs
Since the sceneGraph
reference is passed in as an input and the NgtCanvas
will render the scene graph with the custom renderer, there is no straightforward way to pass Inputs to the scene graph component itself.
Use a shared service or a shared Signal
to pass data from outside to the Scene Graph component.
Custom Inject Functions
All of injectNgt*
functions have been renamed to just inject*
instead.
NgtSignalStore
While not common, consumers can use signalStore()
to create a NgtSignalStore
. The purpose of NgtSignalStore
is a minimal store implementation that angular-three
uses internally.
Methods
-
select(...keys, options?)
: Retrieves a Signal of a part of the state.- Can select nested properties using multiple arguments
- Returns
Signal<T>
where T is the type of the selected state
-
get(...keys)
: Retrieves the current value of a part of the state.- Can access nested properties using multiple arguments
- Returns the value directly, not wrapped in a Signal
-
update(stateOrUpdater)
: Updates the state.- Accepts a partial state object or an updater function
- Updater function receives the previous state and returns a partial state
-
state
: A Signal representing the entire state.- Equivalent to
select()
without arguments
- Equivalent to
-
snapshot
: A getter that returns the current state value.- Equivalent to
get()
without arguments
- Equivalent to
Creation
Created using the signalStore
function:
Signals everywhere
All public APIs return Signal
instead of Observable
. Consumers can try to use toObservable()
to convert it to an Observable
if needed to minimize the changes.
NgtRef
NgtRef
has been removed. Use Signal Query API instead: viewChild
, viewChildren
, contentChild
, and contentChildren
.
Missing components from angular-three-soba
During the work on v2, most components are rewritten from scratch to accommodate the Signal APIs. Hence, there are some components that are missing from previous version of angular-three-soba
.
If you find missing components, please open an issue on Github.