Gathering detailed insights and metrics for wittyna-traceable
Gathering detailed insights and metrics for wittyna-traceable
Gathering detailed insights and metrics for wittyna-traceable
Gathering detailed insights and metrics for wittyna-traceable
npm install wittyna-traceable
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
wittyna-traceable
1npm install wittyna-traceable
以下是几个测试用例的例子
1import { Traceable } from 'wittyna-traceable'; 2import { assert, expect, test } from 'vitest'; 3import { wait } from '../src/utils'; 4import { reactive as reactive2 } from 'vue-2'; 5import { reactive as reactive3 } from 'vue-3'; 6 7const testFn = async (reactive: <T>(t: T) => T = (t) => t) => { 8 const traceable = new Traceable<any>(reactive({ a: 1, b: 2, c: 3 })); 9 traceable.start(); 10 traceable.data.a = 111; 11 await wait(500); 12 traceable.data.b = 222; 13 await wait(500); 14 traceable.data.c = 333; 15 traceable.backward(); 16 expect(JSON.stringify(traceable.data)).eq( 17 JSON.stringify({ a: 1, b: 2, c: 3 }) 18 ); 19}; 20test('basic:start-end', () => testFn()); 21test('vue2:start-end', () => testFn(reactive2 as unknown as <T>(t: T) => T)); 22test('vue3:start-end', () => testFn(reactive3 as unknown as <T>(t: T) => T)); 23
1import { Traceable } from 'wittyna-traceable'; 2import { assert, expect, test } from 'vitest'; 3import { wait } from '../src/utils'; 4import { reactive as reactive2 } from 'vue-2'; 5import { reactive as reactive3 } from 'vue-3'; 6const testFn = async (reactive: <T>(t: T) => T = (t) => t) => { 7 const traceable = new Traceable<any>( 8 reactive({ array: [1, 2, 3, 4, 5, 6, 7] }) 9 ); 10 console.log("原始数据", JSON.stringify(traceable.data)) 11 traceable.data.array.splice(2, 4); 12 traceable.data.array.push('push'); 13 traceable.data.array.push('push'); 14 traceable.data.array.unshift('unshift'); 15 traceable.data.array.unshift('unshift'); 16 traceable.data.array.pop(); 17 traceable.data.array.shift(); 18 traceable.data.array.reverse(); 19 console.log("操作后的数据", JSON.stringify(traceable.data)) 20 expect(JSON.stringify(traceable.data.array)).eq( 21 JSON.stringify(['push', 7, 2, 1, 'unshift']) 22 ); 23 expect(traceable.data.array.length).eq(5); 24 await wait(); 25 traceable.backward(); 26 console.log("回退后数据", JSON.stringify(traceable.data)) 27 expect(JSON.stringify(traceable.data.array)).eq( 28 JSON.stringify([1, 2, 3, 4, 5, 6, 7]) 29 ); 30 expect(traceable.data.array.length).eq(7); 31 await wait(); 32 traceable.forward(); 33 expect(JSON.stringify(traceable.data.array)).eq( 34 JSON.stringify(['push', 7, 2, 1, 'unshift']) 35 ); 36 expect(traceable.data.array.length).eq(5); 37 traceable.backward(); 38 await wait(); 39 40 traceable.data.array.push('push1', 'push2'); 41 expect(JSON.stringify(traceable.data.array)).eq( 42 JSON.stringify([1, 2, 3, 4, 5, 6, 7, 'push1', 'push2']) 43 ); 44 expect(traceable.data.array.length).eq(9); 45 await wait(); 46 traceable.backward(); 47 expect(JSON.stringify(traceable.data.array)).eq( 48 JSON.stringify([1, 2, 3, 4, 5, 6, 7]) 49 ); 50 expect(traceable.data.array.length).eq(7); 51 await wait(); 52 traceable.forward(); 53 expect(JSON.stringify(traceable.data.array)).eq( 54 JSON.stringify([1, 2, 3, 4, 5, 6, 7, 'push1', 'push2']) 55 ); 56 expect(traceable.data.array.length).eq(9); 57}; 58test('basic:type:array', () => testFn()); 59test('vue2:type:array', () => testFn(reactive2 as unknown as <T>(t: T) => T)); 60test('vue3:type:array', () => testFn(reactive3 as unknown as <T>(t: T) => T)); 61
1import { Traceable } from 'wittyna-traceable'; 2import { assert, expect, test } from 'vitest'; 3import { wait } from '../src/utils'; 4import { reactive as reactive2 } from 'vue-2'; 5import { reactive as reactive3 } from 'vue-3'; 6const testFn = async (reactive: <T>(t: T) => T = (t) => t) => { 7 const traceable = new Traceable<any>( 8 reactive({ object: { a: 1, b: 2, c: 3 } }) 9 ); 10 traceable.data.object.a = 'a'; 11 traceable.data.object.b = 'b'; 12 delete traceable.data.object.c; 13 Object.assign(traceable.data.object); 14 15 expect(JSON.stringify(traceable.data.object)).eq( 16 JSON.stringify({ a: 'a', b: 'b' }) 17 ); 18 expect('c' in traceable.data.object).eq(false); 19 await wait(); 20 traceable.backward(); 21 expect(JSON.stringify(traceable.data.object)).eq( 22 JSON.stringify({ a: 1, b: 2, c: 3 }) 23 ); 24 expect('c' in traceable.data.object).eq(true); 25 await wait(); 26 traceable.forward(); 27 expect(JSON.stringify(traceable.data.object)).eq( 28 JSON.stringify({ a: 'a', b: 'b' }) 29 ); 30 expect('c' in traceable.data.object).eq(false); 31}; 32test('basic:type:object', () => testFn()); 33test('vue2:type:object', () => testFn(reactive2 as unknown as <T>(t: T) => T)); 34test('vue3:type:object', () => testFn(reactive3 as unknown as <T>(t: T) => T));
No vulnerabilities found.
No security vulnerabilities found.