1.0.0-beta.6 • Published 1 year ago

@runafe/observable-slim v1.0.0-beta.6

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Fork of 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.
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
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