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

feat: create instanceService #733

Merged
merged 14 commits into from
Jun 7, 2022
Merged
Prev Previous commit
Next Next commit
docs: update docs
  • Loading branch information
mortalYoung committed Jun 2, 2022
commit 7f43e23a10badc0ba92a6ee106c6aa4d2ab0c9ae
12 changes: 6 additions & 6 deletions README-koKR.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ yarn add @dtinsight/molecule
```javascript
import React from 'react';
import ReactDOM from 'react-dom';
import { MoleculeProvider, Workbench } from '@dtinsight/molecule';
import { create, Workbench } from '@dtinsight/molecule';
import '@dtinsight/molecule/esm/style/mo.css';

const App = () => (
<MoleculeProvider extensions={[]}>
<Workbench />
</MoleculeProvider>
);
const moInstance = create({
extensions: [],
});

const App = () => moInstance.render(<Workbench />);

ReactDOM.render(<App />, document.getElementById('root'));
```
Expand Down
12 changes: 6 additions & 6 deletions README-zhCN.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ yarn add @dtinsight/molecule
```javascript
import React from 'react';
import ReactDOM from 'react-dom';
import { MoleculeProvider, Workbench } from '@dtinsight/molecule';
import { create, Workbench } from '@dtinsight/molecule';
import '@dtinsight/molecule/esm/style/mo.css';

const App = () => (
<MoleculeProvider extension={[]}>
<Workbench />
</MoleculeProvider>
);
const moInstance = create({
extensions: [],
});

const App = () => moInstance.render(<Workbench />);

ReactDOM.render(<App />, document.getElementById('root'));
```
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ yarn add @dtinsight/molecule
```javascript
import React from 'react';
import ReactDOM from 'react-dom';
import { MoleculeProvider, Workbench } from '@dtinsight/molecule';
import { create, Workbench } from '@dtinsight/molecule';
import '@dtinsight/molecule/esm/style/mo.css';

const App = () => (
<MoleculeProvider extensions={[]}>
<Workbench />
</MoleculeProvider>
);
const moInstance = create({
extensions: [],
});

const App = () => moInstance.render(<Workbench />);

ReactDOM.render(<App />, document.getElementById('root'));
```
Expand Down
22 changes: 7 additions & 15 deletions website/docs/guides/extend-color-theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,9 @@ Finally, we add the extension package in `App.js`
```js title="src/App.js"
import { OneDarkPro } from './extensions/OneDark-Pro';

function App() {
return (
<MoleculeProvider extensions={[OneDarkPro]}>
<Workbench />
</MoleculeProvider>
);
}
const moInstance = create({
extensions: [OneDarkPro],
});
```

We can use the shortcut key `Command/Ctrl + K` to quickly access the **Color Theme Panel**.
Expand Down Expand Up @@ -215,19 +211,15 @@ export { MyTheme };

### Apply color theme extension

Similarly, custom theme extensions are also need to be introduced in the [MoleculeProvider](../api/classes/MoleculeProvider) component in `App.js`:
Similarly, custom theme extensions are also need to be introduced in the params of [create](../api#create) component in `App.js`:

```js title="src/App.js"
import { OneDarkPro } from './extensions/OneDark-Pro';
import { MyTheme } from './extensions/MyTheme';

function App() {
return (
<MoleculeProvider extensions={[OneDarkPro, MyTheme]}>
<Workbench />
</MoleculeProvider>
);
}
const moInstance = create({
extensions: [OneDarkPro, MyTheme],
});
```

Open **the color theme quick access panel**, we should be able to see the theme of `My Theme`. After selecting this theme, the **background color** of the [StatusBar](extend-workbench#statusbar) at the bottom changes to red.
Expand Down
27 changes: 12 additions & 15 deletions website/docs/guides/extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,30 @@ In some cases, you may want to **disable** some built-in extensions in Molecule.

```ts
import React from 'react';
import molecule from '@dtinsight/molecule';
import { MoleculeProvider, Workbench } from '@dtinsight/molecule';
import molecule, { create, Workbench } from '@dtinsight/molecule';
import '@dtinsight/molecule/esm/style/mo.css';

// All Extension instances
import extensions from './extensions';

molecule.extension.inactive((extension: IExtension) => {
// Inactive the Extension which id is ExampleExt
if (extension.id === 'ExampleExt') {
return true;
}
const moInstance = create({
extensions,
});

function App() {
return (
<MoleculeProvider extensions={extensions}>
<Workbench />
</MoleculeProvider>
);
}
moInstance.onBeforeLoad(() => {
molecule.extension.inactive((ext) => {
// Inactive the Extension which id is ExampleExt
return extension.id === 'ExampleExt';
});
});

const App = () => moInstance.render(<Workbench />);

export default App;
```

:::caution
It should be noted that the [inactive][inactive-url] method needs to be declared before [MoleculeProvider](../api/classes/MoleculeProvider).
It should be noted that the [inactive][inactive-url] method needs to be declared after [create](../api#create).
:::

[inactive-url]: ../api/interfaces/molecule.IExtensionService#inactive
Expand Down
12 changes: 6 additions & 6 deletions website/docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ yarn add @dtinsight/molecule
```javascript
import React from 'react';
import ReactDOM from 'react-dom';
import { MoleculeProvider, Workbench } from '@dtinsight/molecule';
import { create, Workbench } from '@dtinsight/molecule';
import '@dtinsight/molecule/esm/style/mo.css';

const App = () => (
<MoleculeProvider extensions={[]}>
<Workbench />
</MoleculeProvider>
);
const moInstance = create({
extensions: [],
});

const App = () => moInstance.render(<Workbench />);

ReactDOM.render(<App />, document.getElementById('root'));
```
Expand Down
14 changes: 6 additions & 8 deletions website/docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,14 @@ Open the `src/App.js` file and replace the contents of the file with the followi

```js title="src/App.js"
import React from 'react';
import { MoleculeProvider, Workbench } from '@dtinsight/molecule';
import { create, Workbench } from '@dtinsight/molecule';
import '@dtinsight/molecule/esm/style/mo.css';

function App() {
return (
<MoleculeProvider extensions={[]}>
<Workbench />
</MoleculeProvider>
);
}
const moInstance = create({
extensions: [],
});

const App = () => moInstance.render(<Workbench />);

export default App;
```
Expand Down
12 changes: 6 additions & 6 deletions website/docs/the-first-extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Pay more attention: In reality, the **data type** returned by `API.getFolderTree

### Use extension

After defining class `FirstExtension`, it is used with [MoleculeProvider][provider-url]. Here we export all **extension objects** that need to be loaded in `extensions/index.ts` by default:
After defining class `FirstExtension`, it is used with [create][create-url]. Here we export all **extension objects** that need to be loaded in `extensions/index.ts` by default:

```ts title="/src/extensions/index.ts"
import { IExtension } from '@dtinsight/molecule/esm/model';
Expand All @@ -115,12 +115,12 @@ Import the `FirstExtension` object and instantiate it, and finally use `extensio
```tsx title="/src/app.tsx"
import extensions from './extensions';

<MoleculeProvider extensions={extensions}>
<Workbench />
</MoleculeProvider>;
const moInstance = create({
extensions,
});
```

Finally, introduce `extensions` and pass in the `extensions` property of [MoleculeProvider][provider-url].
Finally, introduce `extensions` and pass in the `extensions` property of [create][create-url].

:::info
The above example is just a very simple application scenario. If you want to achieve a richer extension to [Workbench](/guides/extend-workbench.md), you can refer to [Workbench Extension Guide](./guides/extend-workbench.md) ).
Expand All @@ -137,4 +137,4 @@ Please [view][demo-url] the complete source code of **First Extension**

[demo-url]: https://github.com/DTStack/molecule-examples/tree/main/packages/molecule-demo/src/extensions/theFirstExtension
[foldertree-url]: ./guides/extend-builtin-ui#foldertree
[provider-url]: ./api/classes/MoleculeProvider
[create-url]: ./api#create
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,11 @@ export { OneDarkPro };
```js title="src/App.js"
import { OneDarkPro } from './extensions/OneDark-Pro';

function App() {
return (
<MoleculeProvider extensions={[OneDarkPro]}>
<Workbench />
</MoleculeProvider>
);
}
const moInstance = create({
extensions: [OneDarkPro],
});

const App = () => moInstance.render(<Workbench />);
```

我们可以通过快捷键 `Command/Ctrl + K` 快速访问**「颜色主题面板」**。
Expand Down Expand Up @@ -216,19 +214,17 @@ export { MyTheme };

### 应用颜色主题扩展

同样, 自定义的主题扩展程序也是在 `App.js` 中的 [MoleculeProvider](../api/classes/MoleculeProvider) 组件中引入
同样, 自定义的主题扩展程序也是在 `App.js` 中的 [create](../api#create) 方法中传入

```js title="src/App.js"
import { OneDarkPro } from './extensions/OneDark-Pro';
import { MyTheme } from './extensions/MyTheme';

function App() {
return (
<MoleculeProvider extensions={[OneDarkPro, MyTheme]}>
<Workbench />
</MoleculeProvider>
);
}
const moInstance = create({
extensions: [OneDarkPro, MyTheme],
});

const App = () => moInstance.render(<Workbench />);
```

打开在**颜色主题快速访问面板**,我们应该就能看到 `My Theme` 的主题了。选择该主题后,底部 [StatusBar](extend-workbench#状态栏statusbar) 的**背景颜色**即变成了红色。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,30 @@ molecule.extension.getExtension(extensionId);
```ts
import React from 'react';
import molecule from '@dtinsight/molecule';
import { MoleculeProvider, Workbench } from '@dtinsight/molecule';
import { create, Workbench } from '@dtinsight/molecule';
import '@dtinsight/molecule/esm/style/mo.css';

// All Extension instances
import extensions from './extensions';

molecule.extension.inactive((extension: IExtension) => {
// Inactive the Extension which id is ExampleExt
if (extension.id === 'ExampleExt') {
return true;
}
const moInstance = create({
extensions,
});

function App() {
return (
<MoleculeProvider extensions={extensions}>
<Workbench />
</MoleculeProvider>
);
}
moInstance.onBeforeLoad(() => {
molecule.extension.inactive((ext) => {
// Inactive the Extension which id is ExampleExt
return extension.id === 'ExampleExt';
});
});

const App = () => moInstance.render(<Workbench />);

export default App;
```

:::caution
需要注意到是,[inactive][inactive-url] 方法,需要在 [MoleculeProvider](../api/classes/MoleculeProvider) 之前声明
需要注意到是,[inactive][inactive-url] 方法,需要在 [create](../api#create) 导出的生命周期 onBeforeLoad 中使用。
:::

[inactive-url]: ../api/interfaces/molecule.IExtensionService#inactive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ yarn add @dtinsight/molecule
```javascript
import React from 'react';
import ReactDOM from 'react-dom';
import { MoleculeProvider, Workbench } from '@dtinsight/molecule';
import { create, Workbench } from '@dtinsight/molecule';
import '@dtinsight/molecule/esm/style/mo.css';

const App = () => (
<MoleculeProvider extensions={[]}>
<Workbench />
</MoleculeProvider>
);
const moInstance = create({
extensions: [],
});

const App = () => moInstance.render(<Workbench />);

ReactDOM.render(<App />, document.getElementById('root'));
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,14 @@ npm install @dtinsight/molecule

```js title="src/App.js"
import React from 'react';
import { MoleculeProvider, Workbench } from '@dtinsight/molecule';
import { create, Workbench } from '@dtinsight/molecule';
import '@dtinsight/molecule/esm/style/mo.css';

function App() {
return (
<MoleculeProvider extensions={[]}>
<Workbench />
</MoleculeProvider>
);
}
const moInstance = create({
extensions: [],
});

const App = () => moInstance.render(<Workbench />);

export default App;
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function handleSelectFolderTree() {

### 使用扩展

定义好的 `FirstExtension` 对象,最后需要配合 [MoleculeProvider][provider-url] 来使用。这里我们默认在 `extensions/index.ts` 中导出所有需要加载的**扩展对象**:
定义好的 `FirstExtension` 对象,最后需要配合 [create][create-url] 来使用。这里我们默认在 `extensions/index.ts` 中导出所有需要加载的**扩展对象**:

```ts title="/src/extensions/index.ts"
import { IExtension } from '@dtinsight/molecule/esm/model';
Expand All @@ -109,17 +109,17 @@ const extensions: IExtension[] = [new FirstExtension()];
export default extensions;
```

导入 `FirstExtension` 对象并将其实例化,最后使用 `extensions` 导出所有**扩展对象实例**。
导入 `FirstExtension` 对象并将其实例化,最后使用 `create` 传入所有**扩展对象实例**。

```tsx title="/src/app.tsx"
import extensions from './extensions';

<MoleculeProvider extensions={extensions}>
<Workbench />
</MoleculeProvider>;
const moInstance = create({
extensions,
});
```

最后,引入 `extensions` 并传入 [MoleculeProvider][provider-url] 的 `extensions` 属性
最后,引入 `extensions` 并传入 [create][create-url] 的 `extensions` 参数

:::info
上例只是一个很简单的应用场景,想要实现对 [Workbench](/guides/extend-workbench.md) 更丰富的扩展,可以参考 [工作台扩展指南](./guides/extend-workbench.md)。
Expand All @@ -135,4 +135,4 @@ import extensions from './extensions';

[demo-url]: https://github.com/DTStack/molecule-examples/tree/main/packages/molecule-demo/src/extensions/theFirstExtension
[foldertree-url]: ./guides/extend-builtin-ui#文件树foldertree
[provider-url]: ./api/classes/MoleculeProvider
[create-url]: ./api#create