-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
@@ -11,6 +11,7 @@ I.E. don't use Angular templating to create grid items as that is harder to sync | |||
MyComponent HTML | |||
|
|||
```html | |||
|
There was a problem hiding this comment.
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>(); |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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: { |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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...
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.
Checklist
yarn test
)