bytedance / magic-microservices Goto Github PK
View Code? Open in Web Editor NEWMake Web Components easier and powerful!😘
License: MIT License
Make Web Components easier and powerful!😘
License: MIT License
关于UMD打包,vue/react的示例,希望可以补充一下
it looks like this lib only resolve the component cross framework problems. but when we need transform a whole application into a web component. it will be difficult.
angular1.x项目需要怎么使用react组件呢?
wrapper 的样式怎么修改呢,找了下没有相关 API 代码中也是直接写的 width=100% height=100%,能否增加个相关能力
magic 组件如果有自己的样式,或者脚本文件,可以通过 magic 函数第三个字段中的 styles 跟 scripts 进行加载。建议完善 readme.md
magic('my-component', MyModule, {
propTypes: {
id: Number,
test: Boolean,
callback: Function,
count: Number,
},
// 样式文件
styles: ['https://xxx.a.css', 'https://xxx.b.css'],
// js 资源
scripts: ['https://xxx.a.js', 'https://xxx.b.js']
});
<custom-component props={{ a: 1, b: 2 }} />
...
magic('custom-component', {
mount: (container, props) => {
console.log('mount', props)
ReactDOM.render(React.createElement(TheComp, props, null), container)
}
})
mount 无法得到 props 信息
希望有个基于React或Vue的demo,演示一下整个使用流程
在什么情况下比较好用,为什么要用这个。
A caveat to readme.md's vue demo is that if a module is reused more than once on the same page, vueInstance can be shared more than once. react won't have this problem because the reatc update is based on container, which is unique.
import Vue from 'vue/index';
import App from './component/Hello.vue';
let vueInstance = null;
export async function bootstrap() {
console.log('vue app bootstraped');
}
export async function mount(container, props) {
console.log('magic-microservices-component-vue mount >>> ', props);
vueInstance = Vue.createApp({
...App,
data() {
return props;
},
}).mount(container);
}
export async function updated(attrName, value) {
console.log('magic-microservices-component-vue update', attrName, ' >>> ', value);
vueInstance[attrName] = value;
vueInstance.$forceUpdate();
}
export async function unmount() {
console.log('vue app will unmount');
}
import { createApp } from 'vue';
import App from './App.vue';
/**
* Multiple vue instances are identified by container as unique identifiers
*/
const vueInstanceMap = new WeakMap();
export async function mount(container: Element, props: any) {
const vueInstance = createApp({
...App,
data() {
return props;
},
}).mount(container);
vueInstanceMap.set(container, vueInstance)
}
export async function updated(attrName: string, value: any, container: Element,) {
const vueInstance = vueInstanceMap.get(container);
vueInstance[attrName] = value;
vueInstance.$forceUpdate();
}
export function unmount(magicInstance: any, container: any) {
const vueInstance = vueInstanceMap.get(container);
vueInstance.unmount();
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.