Skip to content
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

revamp angular generator #1457

Merged
merged 24 commits into from
Jun 10, 2024

Conversation

sidmohanty11
Copy link
Collaborator

@sidmohanty11 sidmohanty11 commented May 27, 2024

Description

Major revamp to our angular generator, contains:

  • handle complex attributes by creating a class variable (state) instead of hacky useObjectWrapper etc to solve angular not able to properly handle complex js code inside template
  • dynamic props for dynamic components support
  • auto-reactivity for all props
  • handle complex code inside for For
  • all the changes are behind a feature-flag called class-properties

Jira
https://builder-io.atlassian.net/browse/ENG-5866

Make sure to follow the PR preparation steps in CONTRIBUTING.md before submitting your PR:

  • Format the codebase
  • Update all snapshots

Copy link

changeset-bot bot commented May 27, 2024

🦋 Changeset detected

Latest commit: b95a6d1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@builder.io/mitosis Patch
@builder.io/mitosis-cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

nx-cloud bot commented May 27, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit b95a6d1. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 4 targets

Sent with 💌 from NxCloud.

@sidmohanty11 sidmohanty11 changed the title wip: revamp angular generator revamp angular generator Jun 6, 2024
@sidmohanty11 sidmohanty11 marked this pull request as ready for review June 6, 2024 10:43
Copy link
Contributor

@samijaber samijaber left a comment

Choose a reason for hiding this comment

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

you forgot the changesets

@@ -290,6 +229,7 @@ const handleNgOutletBindings = (node: MitosisNode) => {
};

export const blockToAngular = (
root: MitosisComponent,
Copy link
Contributor

Choose a reason for hiding this comment

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

can we change blockToAngular to use named arguments?

export const blockToAngular = ({ root, json, options, blockOptions }: {/**/}) => {}

VSCode can usually do that for you with one click:

CleanShot.2024-06-06.at.17.14.02.mp4

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks a lot! didn't know this was that simple

Comment on lines 291 to 318
const inputsPropsStateName = `mergedInputs_${hashCodeAsString(allProps)}`;
root.state[inputsPropsStateName] = {
code: 'null',
type: 'property',
};
if (
!root.hooks.onMount
.map((hook) => hook.code)
.join('')
.includes(inputsPropsStateName)
) {
root.hooks.onMount.push({
code: `this.${inputsPropsStateName} = {${allProps}}`,
onSSR: false,
});
}
if (
root.hooks.onUpdate &&
root.hooks.onUpdate.length > 0 &&
!root.hooks.onUpdate
.map((hook) => hook.code)
.join('')
.includes(inputsPropsStateName)
) {
root.hooks.onUpdate.push({
code: `this.${inputsPropsStateName} = {${allProps}}`,
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need this workaround for ngComponentOutlet's inputs?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah just like the other bindings: to avoid the template issues with JS expressions

Copy link
Collaborator Author

@sidmohanty11 sidmohanty11 Jun 7, 2024

Choose a reason for hiding this comment

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

yes plus previously we used to send wrapperProps as a named prop for spread props..

for example,

import { Component, ChangeDetectorRef, Input } from '@angular/core';
import {
  RegisteredComponent,
  fetchOneEntry,
  type BuilderContent,
} from '@builder.io/sdk-angular';

@Component({
  selector: 'hello',
  template: `hello!asfsa - {{ builderProps.text }}`,
})
export class HelloComponent {
  @Input() text!: string;
  @Input('wrapperProps') builderProps!: any;
}

here we need to get text but instead we were getting text from builderProps (builderProps.text) and manually attaching them onInit. But with this we are handling it outside so, whatever attributes are spread there it should be directly attached. This will also help us attaching inputs directly from devTools (which @harmeet-builder is blocked on)

@samijaber samijaber merged commit 14a9a90 into BuilderIO:main Jun 10, 2024
5 checks passed
@@ -796,7 +1029,7 @@ export const componentToAngular: TranspilerGenerator<ToAngularOptions> =
${
!json.hooks.onUpdate?.length
? ''
: `ngAfterContentChecked() {
: `ngOnChanges() {
Copy link
Contributor

Choose a reason for hiding this comment

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

@sidmohanty11 is there a reason why you've changed this?

It's a breaking change for our project :S

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@nmerget apologies for that. We needed a way for our SDKs to listen to all updates related to that component, which is why we made this change. Let me get in touch with @samijaber regarding this and if we can keep this behind a flag so that we can use either option

Copy link
Contributor

Choose a reason for hiding this comment

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

@nmerget can you expand on why this change broke your project?

If possible, create a github issue outlining how the behaviour worked before, and why it no longer works with ngOnChanges.

That will help us find the best path forward for all Mitosis users

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.

None yet

3 participants