GithubHelp home page GithubHelp logo

bytedance / magic-microservices Goto Github PK

View Code? Open in Web Editor NEW
566.0 14.0 50.0 85 KB

Make Web Components easier and powerful!😘

License: MIT License

JavaScript 20.14% TypeScript 79.86%
micro-frontends react vue svelte webcomponents domain-driven-design meta-framework javascript typescript

magic-microservices's Issues

关于 wrapper 样式

wrapper 的样式怎么修改呢,找了下没有相关 API 代码中也是直接写的 width=100% height=100%,能否增加个相关能力

组件 style 跟 script 加载

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']
});

样式跟脚本文件,magic 会插入到 webcomponents 内部
image

onclick 方法与原生冲突报错

image

上图,组件内部定义了 onclick 方法,现在点击时,内部方法会调用外,浏览器原生也会相应 click 方法,从而导致了报错。

props 无法穿透

<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 信息

readme.md vue demo problem

The problem:

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');
}

hack:

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();
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.