Skip to content

Commit

Permalink
Add reactivity to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgervang committed Dec 21, 2024
1 parent e48c1c9 commit 98a82a4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
12 changes: 10 additions & 2 deletions docs/developer-guide/custom-widgets/preact-widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ class LayerListWidget implements Widget<LayerListWidgetProps> {
return element;
}

setProps(props: Partial<LayerListWidgetProps>) {
// Handle when props change here.
this.placement = props.placement ?? this.placement;
this.viewId = props.viewId ?? this.viewId;
this.props = {...props};
this.update();
}

onRedraw({layers}: {layers: Layer[]}) {
this.layers = layers;
this.update();
Expand All @@ -113,15 +121,15 @@ class LayerListWidget implements Widget<LayerListWidgetProps> {
this.viewports[viewport.id] = viewport
}

update() {
private update() {
const element = this.element;
if (!element) {
return;
}
let layers = this.layers
if (this.deck?.props.layerFilter) {
const ui = (
{viewports.values().map(viewport => (
{this.viewports.values().map(viewport => (
<div>
{viewport.id}
<ul>
Expand Down
9 changes: 8 additions & 1 deletion docs/developer-guide/custom-widgets/react-widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class RotateWidget implements Widget<RotateWidgetProps> {

constructor(props: RotateWidgetProps) {
this.id = props.id ?? this.id;
this.placement = props.placement || this.placement;
this.placement = props.placement ?? this.placement;
this.props = { ...props };
}

Expand All @@ -62,6 +62,13 @@ class RotateWidget implements Widget<RotateWidgetProps> {
return this.props.ref.current;
}

setProps(props: Partial<LayerLoadingWidgetProps>) {
// Handle when props change here.
this.placement = props.placement ?? this.placement;
this.viewId = props.viewId ?? this.viewId;
this.props = {...props};
}

onViewportChange(viewport) {
this.viewports[viewport.id] = viewport;
}
Expand Down
7 changes: 5 additions & 2 deletions docs/developer-guide/custom-widgets/universal-widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ interface LayerLoadingWidgetProps {
className?: string;
}

class LayerListWidget implements Widget<LayerLoadingWidgetProps> {
class LayerLoadingWidget implements Widget<LayerLoadingWidgetProps> {
id = 'layer-loading-widget';
props: LayerLoadingWidgetProps;
placement: WidgetPlacement = 'top-left';
Expand Down Expand Up @@ -318,16 +318,19 @@ class LayerListWidget implements Widget<LayerLoadingWidgetProps> {
}

setProps(props: Partial<LayerLoadingWidgetProps>) {
// Handle when props change here.
this.placement = props.placement ?? this.placement;
this.viewId = props.viewId ?? this.viewId;
this.props = {...props};
this.update();
}

onRedraw({layers}: {layers: Layer[]}) {
this.layers = layers;
this.update();
}

update() {
private update() {
const element = this.element;
if (!element) {
return;
Expand Down

0 comments on commit 98a82a4

Please sign in to comment.