Skip to content

Commit

Permalink
fix: mergedInputs reactivity in angular (#1524)
Browse files Browse the repository at this point in the history
* fix: mergedInputs reactivity in angular

* changeset

* Update .changeset/large-hats-peel.md

Co-authored-by: Sami Jaber <[email protected]>

---------

Co-authored-by: Sami Jaber <[email protected]>
  • Loading branch information
sidmohanty11 and samijaber authored Aug 7, 2024
1 parent b071783 commit 03f1f58
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-hats-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@builder.io/mitosis': patch
---

Angular: Fix: reactivity of `mergedInputs` (used in Dynamic components)
Original file line number Diff line number Diff line change
Expand Up @@ -2536,6 +2536,12 @@ export default class MyBasicForNoTagRefComponent {
this.vcRef.createEmbeddedView(this.iconTemplateRef).rootNodes,
];
}

ngOnChanges() {
if (typeof window !== \\"undefined\\") {
this.mergedInputs_0 = {};
}
}
}

@NgModule({
Expand Down Expand Up @@ -3186,6 +3192,17 @@ export default class MyComponent {
...this.something,
};
}

ngOnChanges() {
if (typeof window !== \\"undefined\\") {
this.mergedInputs_mlw9p4 = {
hello: \\"world\\",
onClick: this.onClick.bind(this),
...this.attributes,
...this.something,
};
}
}
}

@NgModule({
Expand Down Expand Up @@ -3258,6 +3275,17 @@ export default class MyComponent {
this.vcRef.createEmbeddedView(this.componentTemplateRef).rootNodes,
];
}

ngOnChanges() {
if (typeof window !== \\"undefined\\") {
this.mergedInputs_mlw9p4 = {
hello: \\"world\\",
onClick: this.onClick.bind(this),
...this.attributes,
...this.something,
};
}
}
}

@NgModule({
Expand Down Expand Up @@ -8470,6 +8498,12 @@ export default class MyBasicForNoTagRefComponent {
this.vcRef.createEmbeddedView(this.iconTemplateRef).rootNodes,
];
}

ngOnChanges() {
if (typeof window !== \\"undefined\\") {
this.mergedInputs_0 = {};
}
}
}

@NgModule({
Expand Down Expand Up @@ -9167,6 +9201,17 @@ export default class MyComponent {
...this.something,
};
}

ngOnChanges() {
if (typeof window !== \\"undefined\\") {
this.mergedInputs_mlw9p4 = {
hello: \\"world\\",
onClick: this.onClick.bind(this),
...this.attributes,
...this.something,
};
}
}
}

@NgModule({
Expand Down Expand Up @@ -9240,6 +9285,17 @@ export default class MyComponent {
this.vcRef.createEmbeddedView(this.componentTemplateRef).rootNodes,
];
}

ngOnChanges() {
if (typeof window !== \\"undefined\\") {
this.mergedInputs_mlw9p4 = {
hello: \\"world\\",
onClick: this.onClick.bind(this),
...this.attributes,
...this.something,
};
}
}
}

@NgModule({
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/generators/angular/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,14 @@ export const blockToAngular = ({
root.hooks.onInit.code += `\nthis.${inputsPropsStateName} = {${allProps}};\n`;
}
if (
root.hooks.onUpdate &&
root.hooks.onUpdate.length > 0 &&
!root.hooks.onUpdate
.map((hook) => hook.code)
?.map((hook) => hook.code)
.join('')
.includes(inputsPropsStateName)
) {
if (!root.hooks.onUpdate) {
root.hooks.onUpdate = [];
}
root.hooks.onUpdate.push({
code: `this.${inputsPropsStateName} = {${allProps}}`,
});
Expand Down

0 comments on commit 03f1f58

Please sign in to comment.