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

Add support for dynamically resolved URLs #28

Open
gshokanov opened this issue Oct 14, 2019 · 3 comments
Open

Add support for dynamically resolved URLs #28

gshokanov opened this issue Oct 14, 2019 · 3 comments
Labels
enhancement New feature or request in progress

Comments

@gshokanov
Copy link
Contributor

Hi 👋
I have encountered the following issue with this package: it is impossible to dynamically resolve URLs at runtime while still compiling using AOT.
I have a use case where the URL is resolved dynamically at runtime in a sync way. This URL may be configured by the running sub-application or it may be configured by one of web-components.
The API looks somewhat like this:

const lazyElementConfig: LazyElementModuleOptions = {
  elementConfigs: [
    { tag: 'ba-menu', url: resolveUrl('ba-menu') }
  ]
}

My team uses a custom package to store some data on the window object to share it between micro-frontends. This data is resolved before the application's bootstrap.
But during the compilation, Angular aggressively optimizes this value to undefined, which obviously breaks the application.
Currently, the workaround is to manually provide URLs to the directive in templates.
I think it could be fixed if elementConfigs could accept url as a function that resolves to URL value.
Could you please look into it? I'd be happy to contribute if you need any help.

@tomastrajan
Copy link
Member

Hi @MagicCurlyHair !

As you said, you can currently use directive directly , but I understand it would be nicer experience if you could also pre-configure it in a central location.

And yes the main cause of this is Angulars AOT compilation...

Static javascript function are well supported by the AOT compilation so passing one in the config should work...

As for the impl, we could check if the value is string or function and call it if its a function but it should be sync!

One more question would be if we should.support this for every prop or just make the whole config either object or a function which returns a config object which sounds more reasonable.

Would you have a look and make it happen ?

@gshokanov
Copy link
Contributor Author

@tomastrajan
Great idea with the function returning the whole config object! I think this is the better option.

Regarding the function itself, I know that it must be sync, this is not a problem.

I should have some spare time by the end of the week, I will look into it and make a PR.

@felipeplets
Copy link
Contributor

@gshokanov I know it is not the same thing, but there is a feature that we introduced in 10.1 that allow using import maps that allows dynamic URL definition.

Check the example "Using import maps (SystemJS is required)" in the documentation:
https://angular-extensions.github.io/elements/#/examples/basic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request in progress
Projects
None yet
Development

No branches or pull requests

3 participants