Thanks to visit codestin.com
Credit goes to github.com

Skip to content

angular: update BaseWidget.deserialize to set values on model() signals #3025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

josueggh
Copy link

Description

Update BaseWidget to initialize writable signals via model<T>() without breaking existing @Input bindings. Metioned in #2950 .

Usage docs in the README have been updated, and a new demo section has been added.

this.gridComp()?.grid?.addWidget({
  autoPosition: true,
  w: 2,
  h: 4,
  selector: 'angular-signal-based',
  input: {
    title: 'Item #' + id + ' (signal)',
    x: 'Item #' + id + ' (signal)',
    id
  },
  id: String(this.ids),
} as NgGridStackWidget);

export class SignalBasedComponent extends BaseWidget {
  title: ModelSignal<string | undefined> = model<string>();
  description: ModelSignal<string | undefined> = model<string>();
  id: ModelSignal<number> = model<number>(0);

  computedValue: Signal<"#FFF" | "#000"> = computed(() => {
    return this.id() % 2 ? '#FFF' : '#000';
  })
}

Checklist

  • Created tests which fail without the change (if possible)
  • All tests passing (yarn test)
  • Extended the README / documentation, if necessary

@@ -11,6 +11,7 @@ I.E. don't use Angular templating to create grid items as that is harder to sync
MyComponent HTML

```html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert all your formatting changes please.

```typescript
// Component expecting input as signals
export class SignalBasedComponent extends BaseWidget {
title: ModelSignal<string | undefined> = model<string>();
Copy link
Member

@adumesny adumesny May 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the benefit to using readonly signal and have to write all that woraround code, when @input() works just fine with latest Angular and you can still have set/get if you want ot be notified of changes...

"@angular/platform-browser": "^14",
"@angular/platform-browser-dynamic": "^14",
"@angular/router": "^14",
"@angular/animations": "^17",
Copy link
Member

@adumesny adumesny May 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no. I intentionally DO NOT use latest rev so Ang14-18+ can use the published bits. please revert.


import { GridStack } from 'gridstack';
import { GridstackComponent, NgGridStackOptions, NgGridStackWidget } from 'gridstack/dist/angular';
import { BaseWidget } from '../../../lib/src';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likely wrong import

minRow: 1,
float: true,
column: 12,
columnOpts: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessarry for signal demo. simplify.

id: ModelSignal<number> = model<number>(0);

computedValue: Signal<"#FFF" | "#000"> = computed(() => {
return this.id() % 2 ? '#FFF' : '#000';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make 2 shade of grey (B vs W won't render text)


/**
* REDEFINE this if your widget needs to read from saved data and transform it to create itself - you do this for
* things that are not mapped directly into @Input() fields for example.
*/
public deserialize(w: NgGridStackWidget) {
// save full description for meta data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would you remove my comment ?

const prop = (this as any)[key];

if (typeof prop === 'function' && 'set' in prop) {
(prop as WritableSignal<unknown>).set(value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this will be done in older angular (say 14 we have today. I didn't check when signal came in...

@adumesny
Copy link
Member

adumesny commented May 4, 2025

honestly I need to understand to clear benefit of signal for widget inputs vs simple @input()/@output() and set/get that work just fine... just becuase signal are the new thing, not clear to me what we gain here with all that extra machinery....

@josueggh josueggh marked this pull request as draft May 5, 2025 08:05
@josueggh josueggh closed this May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants