Skip to content

Latest commit

 

History

History
101 lines (69 loc) · 2.52 KB

README_CN.md

File metadata and controls

101 lines (69 loc) · 2.52 KB

iofod-sdk

Version NPM Build Status License

iofod SDK 提供开发者在 Web worker 里与 iofod 主界面交互的能力,通过 SDK 来快速开发 iofod 拓展。详细文档请参考:拓展 SDK

开发准备

我们推荐使用 Node.js v16.15.0 版本进行 iofod 拓展开发,我们目前所有的拓展几乎都使用该版本。

安装

yarn 安装:

yarn add iofod-sdk -D

npm 安装:

npm install iofod-sdk -D

使用

正式环境下,开发者无需额外引入 SDK 文件,拓展在 iofod 里初始化过程中自动执行加载 SDK 并挂载到全局变量 PLUS 上。

本地开发调试建议通过这种方式使用 SDK:

import * as PLUS from 'iofod-sdk'

拓展的样板

所有拓展都应该具备初始化入口 main 函数,在 main 函数体里执行 SDK 初始化和拓展界面渲染。

示例:

export async function main() {
  await PLUS.init({
    state: { ... },
    version: '1.0.0'
  });

  await PLUS.render([...]);
}

拓展内置组件

iofod 拓展的界面通过拓展组件来绘制并实现拓展与用户交互。可以参考使用说明

结合拓展 SDK 和内置组件,我们很容易就能开发一个拓展,利用 iofod 里的拓展能力,为项目提供更多的定制性,发掘更多可能。

示例:

const { Button } = PLUS.components

export async function main() {
  await PLUS.init({
    state: {
      msg: 'click me!',
      showMsg: false,
    },
    version: '1.0.0',
  })

  await PLUS.render([
    Button('$msg', 'clickBinding'),
    Text({
      render: '$showMsg',
      value: 'QAQ',
    }),
  ])
}

export async function clickBinding(e) {
  console.log(e)

  PLUS.setState({
    showMsg: true,
  })
}

更多

更多内容请阅读官方文档获取,模板和案例可以参考官方开源库

许可证

BSD 3-Clause

Copyright (c) 2022-present, iofod.