# miniprogram-composition

> 小程序composition式api

Latest version **0.0.16** (published 2023-09-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install miniprogram-composition
pnpm add miniprogram-composition
yarn add miniprogram-composition
bun add miniprogram-composition
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.16 |
| Published | 2023-09-18 |
| First published | 2023-06-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 21.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | zc1075488066 |

## Links

- npm: https://www.npmjs.com/package/miniprogram-composition
- npm.io page: https://npm.io/package/miniprogram-composition

## Dependencies (2)

- [mobx-miniprogram](https://npm.io/package/mobx-miniprogram.md) ^4.13.2
- [@types/wechat-miniprogram](https://npm.io/package/@types/wechat-miniprogram.md) ^3.4.1

## Recent versions

- 0.0.16 (latest) — 2023-09-18
- 0.0.15 — 2023-09-18
- 0.0.14 — 2023-09-16
- 0.0.13 — 2023-09-12
- 0.0.12 — 2023-09-12
- 0.0.11 — 2023-09-12
- 0.0.9 — 2023-09-11
- 0.0.8 — 2023-09-09
- 0.0.7 — 2023-09-07
- 0.0.6 — 2023-09-07
- 0.0.5 — 2023-06-29
- 0.0.4 — 2023-06-29
- 0.0.2 — 2023-06-26
- 0.0.1 — 2023-06-20

## README

# miniprogram-composition

[![NPM version](https://img.shields.io/npm/v/miniprogram-composition.svg?style=flat)](https://npmjs.org/package/miniprogram-composition)
[![NPM downloads](http://img.shields.io/npm/dm/miniprogram-composition.svg?style=flat)](https://npmjs.org/package/miniprogram-composition)

小程序 mobx composition api

## Usage

TODO

## Options

TODO

## Development

```html
<!--index.wxml-->
<view style="padding: 60px;">
  <viw bintap="increment">{{count}}</viw>
  <viw>{{countPlus}}</viw>
</view>
```

```javascript
//使用包装过的函数 支持ts类型提示
import { ComponentWithComposition, onDetached } from 'miniprogram-composition';
import { computed, observable } from 'mobx-miniprogram';

ComponentWithComposition({
  properties: {},
  setup() {
    onDetached(() => {
      //组件卸载了
    });
    const count = observable.box(0);
    const countPlus = computed(() => {
      return count.get() + 1;
    });
    const increment = () => {
      count.set(count.get() + 1);
    };
    count.observe(({ oldValue, newValue }) => {
      console.log('count变化了新值是', newValue, '之前的值是', oldValue);
    });
    const decrement = () => {
      count.set(count.get() - 1);
    };

    //方法添加到this 状态添加到this.data
    return {
      countPlus,
      count,
      increment,
    };
  },
  methods: {
    click() {
      this.increment();
      console.log(this.data.count);
    },
  },
});
```

## LICENSE

MIT

---
_Source: https://npm.io/package/miniprogram-composition · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
