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

fix: 🐛 jsx syntax used in js file #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 51 additions & 81 deletions docs/pack/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,12 @@ const { bus, setupApp, preloadApp, destroyApp } = WujieReact;
## 原理

```javascript
import React from "react";
import React, { createElement } from "react";
import PropTypes from "prop-types";
import { bus, setupApp ,preloadApp, startApp, destroyApp } from "wujie";
import { bus, preloadApp, startApp, destroyApp, setupApp } from "wujie";

export default class WujieReact extends React.PureComponent {
static propTypes = {
height: PropTypes.string,
width: PropTypes.string,
name: PropTypes.string,
loading: PropTypes.element;
url: PropTypes.string,
alive: PropTypes.bool,
fetch: PropTypes.func,
props: PropTypes.object,
replace: PropTypes.func,
Comment on lines -62 to -76
Copy link
Contributor Author

Choose a reason for hiding this comment

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

align to packages/wujie-react/index.js

sync: PropTypes.bool,
prefix: PropTypes.object,
fiber: PropTypes.bool,
degrade: PropTypes.bool,
plugins: PropTypes.array,
beforeLoad: PropTypes.func,
beforeMount: PropTypes.func,
afterMount: PropTypes.func,
beforeUnmount: PropTypes.func,
afterUnmount: PropTypes.func,
activated: PropTypes.func,
deactivated: PropTypes.func,
loadError: PropTypes.func,
};
static propTypes = propTypes;
static bus = bus;
static setupApp = setupApp;
static preloadApp = preloadApp;
Expand All @@ -101,69 +78,62 @@ export default class WujieReact extends React.PureComponent {

startAppQueue = Promise.resolve();

startApp = async () => {
try {
const props = this.props;
const { current: el } = this.state.myRef;
this.destroy = await startApp({
...props,
el,
});
} catch (error) {
console.log(error);
}
};

execStartApp = () => {
const {
name,
url,
loading,
alive,
fetch,
props,
replace,
sync,
prefix,
fiber,
degrade,
plugins,
beforeLoad,
beforeMount,
afterMount,
beforeUnmount,
afterUnmount,
activated,
deactivated,
loadError,
} = this.props;
this.startAppQueue = this.startAppQueue.then(async () => {
try {
this.destroy = await startApp({
name,
url,
el: this.state.myRef.current,
loading,
alive,
fetch,
props,
replace,
sync,
prefix,
fiber,
degrade,
plugins,
beforeLoad,
beforeMount,
afterMount,
beforeUnmount,
afterUnmount,
activated,
deactivated,
loadError,
});
} catch (error) {
console.log(error);
}
});
this.startAppQueue = this.startAppQueue.then(this.startApp);
};

render() {
this.execStartApp();
return React.createElement("div", {

const { width, height } = this.props;
const { myRef: ref } = this.state;
return createElement("div", {
style: {
width: this.props.width,
height: this.props.height,
width,
height,
},
ref: this.state.myRef,
ref,
});
}
}

const propTypes = {
height: PropTypes.string,
width: PropTypes.string,
name: PropTypes.string,
loading: PropTypes.element,
url: PropTypes.string,
alive: PropTypes.bool,
fetch: PropTypes.func,
props: PropTypes.object,
attrs: PropTypes.object,
replace: PropTypes.func,
sync: PropTypes.bool,
prefix: PropTypes.object,
fiber: PropTypes.bool,
degrade: PropTypes.bool,
plugins: PropTypes.array,
beforeLoad: PropTypes.func,
beforeMount: PropTypes.func,
afterMount: PropTypes.func,
beforeUnmount: PropTypes.func,
afterUnmount: PropTypes.func,
activated: PropTypes.func,
deactivated: PropTypes.func,
loadError: PropTypes.func,
};

```
60 changes: 33 additions & 27 deletions packages/wujie-react/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { createElement } from "react";
import PropTypes from "prop-types";
import { bus, preloadApp, startApp, destroyApp, setupApp } from "wujie";

Expand Down Expand Up @@ -28,7 +28,7 @@ export default class WujieReact extends React.PureComponent {
} catch (error) {
console.log(error);
}
}
};

execStartApp = () => {
this.startAppQueue = this.startAppQueue.then(this.startApp);
Expand All @@ -39,32 +39,38 @@ export default class WujieReact extends React.PureComponent {

const { width, height } = this.props;
const { myRef: ref } = this.state;
return <div style={{ width, height }} ref={ref} />;
return createElement("div", {
style: {
width,
height,
},
ref,
});
Comment on lines +42 to +48
Copy link
Contributor Author

@lczzlczz lczzlczz Sep 14, 2022

Choose a reason for hiding this comment

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

use createElement function to create <div> element.

}
}

const propTypes = {
height: PropTypes.string,
width: PropTypes.string,
name: PropTypes.string,
loading: PropTypes.element,
url: PropTypes.string,
alive: PropTypes.bool,
fetch: PropTypes.func,
props: PropTypes.object,
attrs: PropTypes.object,
replace: PropTypes.func,
sync: PropTypes.bool,
prefix: PropTypes.object,
fiber: PropTypes.bool,
degrade: PropTypes.bool,
plugins: PropTypes.array,
beforeLoad: PropTypes.func,
beforeMount: PropTypes.func,
afterMount: PropTypes.func,
beforeUnmount: PropTypes.func,
afterUnmount: PropTypes.func,
activated: PropTypes.func,
deactivated: PropTypes.func,
loadError: PropTypes.func,
}
height: PropTypes.string,
width: PropTypes.string,
name: PropTypes.string,
loading: PropTypes.element,
url: PropTypes.string,
alive: PropTypes.bool,
fetch: PropTypes.func,
props: PropTypes.object,
attrs: PropTypes.object,
replace: PropTypes.func,
sync: PropTypes.bool,
prefix: PropTypes.object,
fiber: PropTypes.bool,
degrade: PropTypes.bool,
plugins: PropTypes.array,
beforeLoad: PropTypes.func,
beforeMount: PropTypes.func,
afterMount: PropTypes.func,
beforeUnmount: PropTypes.func,
afterUnmount: PropTypes.func,
activated: PropTypes.func,
deactivated: PropTypes.func,
loadError: PropTypes.func,
};
Comment on lines +53 to +76
Copy link
Contributor Author

@lczzlczz lczzlczz Sep 14, 2022

Choose a reason for hiding this comment

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

change indentation from 4 spaces to 2 spaces.