# @runafe/observable-slim

> ## purpose

Latest version **1.0.0-beta.6** (published 2022-11-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install @runafe/observable-slim
pnpm add @runafe/observable-slim
yarn add @runafe/observable-slim
bun add @runafe/observable-slim
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-beta.6 |
| Published | 2022-11-14 |
| First published | 2022-11-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 74.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | wangquery |

## Links

- npm: https://www.npmjs.com/package/@runafe/observable-slim
- npm.io page: https://npm.io/package/@runafe/observable-slim

## Recent versions

- 1.0.0-beta.6 (latest) — 2022-11-14
- 1.0.0-beta.5 — 2022-11-14
- 1.0.0-beta.4 — 2022-11-11
- 1.0.0-beta.3 — 2022-11-10
- 1.0.0-beta.2 — 2022-11-09
- 1.0.0-beta.1 — 2022-11-09

## README

# Fork of [observable-slim](https://github.com/elliotnb/observable-slim)

## purpose

For version control of our own low code platform based on `vue3`

## changes

- refactor with Typescript

- batch array changes into one
  - if array operation is oneof `push`, `pop`, `unshift`, `shift`, `splice`, we always want the final array and initial array, unfortunately, `observable-slim` based on `Proxy` always invoke many changs like `array.0`, `array.1`, `array.length` which we don't care anymore, so, I rewrite the origin methods `push, unshift, pop, shift, sort, splice, reverse`, then `change` is just determined by the result and diff by `diffTwoArray` method.

``` javascript
const app = [
  {
    itemId: "appOne",
    code: 1,
    name: 2,
    array1: [
      { itemId: 11, name: "1-1" },
      { itemId: 22, name: "1-2" },
    ],
  },
];

const appProxy = ObservableSlim.create(app, false, (change) => {
  if (change.length) {
    console.log("change", change[0]);
  }
});
const [app] = appReactive;
app.array1.reverse();
app.array1.reverse();
app.array1[0].name = "1-1-2";
app.array1.splice(0, 0, { name: "1-3", itemId: ++index });
delete app.array1[0];
```

- add `__F_` prefix to all private key added by `observable-slim`, like `__length`, `__isProxy`, `__getPath`
- change some key for our own project to use

```typescript
export interface Change {
  isSame: boolean;
  operationType: OperationTypeEnum;
  operation?: ArrayOperation | string;
  newValue: any;
  oldValue: any;
  target: any;
  proxy: any;
  dotPath: string;
  fieldIndex: string; // itemIdPath
  property: string;
  elementIndex?: number;
  sort: number;
}
```

- add `sort` flag for sorting changes
- add more `types` for TS

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