简体   繁体   English

最佳实践:Typescript:让客户使用自定义代码扩展应用程序

[英]Best practice: Typescript: Let a customer extend an application with custom code

we have an angular 9 based application framework, which gives a customer the possibility to configurate an application with fields and layouts.我们有一个基于 angular 9 的应用程序框架,它使客户可以使用字段和布局配置应用程序。 This works pretty nice.这很好用。

But now we get to the point, where a customer wants to implement special features, like "He enters a value into a textfield and a request to a 3rd party software should be fired to load new data and autofill other values".但现在我们到了一点,客户想要实现特殊功能,例如“他在文本字段中输入一个值,并且应该触发对 3rd 方软件的请求以加载新数据并自动填充其他值”。

We could implement every possible interaction or allow to create custom snippets in javascript.我们可以实现所有可能的交互或允许在 javascript 中创建自定义片段。

But in the past i have had a lot of bad experience with these base javascript snippets because they didn't have the needed standard functionality like typescript provides me.但是在过去,我对这些基本的 javascript 片段有很多糟糕的经历,因为它们没有像 typescript 为我提供的所需的标准功能。

1) Is there a way how a user can create custom code during runtime with typescript rather than plane javascript? 1) 有没有办法让用户在运行时使用打字稿而不是平面 javascript 创建自定义代码?

Yes i know typecript needs to be compiled before running, but I ask because I want to know if there is another way?是的,我知道在运行之前需要编译 typecript,但我问是因为我想知道是否有其他方法?

2) Alternative question: Can a user develop an angular application and add it as plugin during runtime? 2) 替代问题:用户可以开发 angular 应用程序并在运行时将其添加为插件吗? Something like an extension or a custom functionality which will be added to the portal for the customer which is not part of the base framework?诸如扩展或自定义功能之类的东西,它们将添加到客户的门户中,而不是基本框架的一部分?

Thanks for your help.谢谢你的帮助。

I don't know if I understand your question well but from my point of view the only way that an other user want to interact with the main Angular project is that he create a library by using the command ng generate library my-lib .我不知道我是否理解你的问题,但从我的角度来看,其他用户想要与主 Angular 项目交互的唯一方法是he create a library使用命令ng generate library my-lib he create a library ( https://angular.io/guide/creating-libraries ) ( https://angular.io/guide/creating-libraries )

From there he can create a new module and then someone else import this new lib into the main project and that's it.从那里他可以创建一个新模块,然后其他人将这个新库导入主项目,就是这样。

The new lib can be maintained by the "customer" and he can release new version of it if the lib is hosted in npm repository and from the main application just need to npm i customer-lib@latest新库可以由“客户”维护,如果库托管在 npm 存储库中并且从主应用程序只需要npm i customer-lib@latest ,他可以发布新版本的库

Did I answerd to your question ?我回答你的问题了吗?

The thing is we have a hosted cloud application, where we have a standard implementation which is already compiled and deployed in a docker container.问题是我们有一个托管的云应用程序,我们有一个标准的实现,它已经编译并部署在一个 docker 容器中。

Now a customer should have the possibility to extend the functionality by adding scripts and modules.现在,客户应该可以通过添加脚本和模块来扩展功能。 Like it is common for example in wordpress.就像在wordpress中很常见。 Where you have a standard implementation and if you want another wysiwyg Editor you install a plugin.如果你有一个标准的实现,如果你想要另一个所见即所得的编辑器,你可以安装一个插件。

I know the only way of injecting code is via javascript but I just wanted to ask if there is another solution for this which will not lead to redploy the whole application.我知道注入代码的唯一方法是通过 javascript,但我只是想问问是否有其他解决方案不会导致重新部署整个应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM