From c16eabbbddf6f1b02e9582b378f427e08a3d0739 Mon Sep 17 00:00:00 2001 From: Carlos Rodrigues Date: Thu, 4 Jun 2020 16:46:32 +0100 Subject: [PATCH 1/7] feat(useUndo): feat `useUndo` composable --- packages/vue-composable/src/misc/index.ts | 1 + packages/vue-composable/src/misc/undo.ts | 66 +++++++++++++++++++++++ packages/vue-composable/src/utils.ts | 2 + 3 files changed, 69 insertions(+) create mode 100644 packages/vue-composable/src/misc/undo.ts diff --git a/packages/vue-composable/src/misc/index.ts b/packages/vue-composable/src/misc/index.ts index 021d5021c..1f3b11fcd 100644 --- a/packages/vue-composable/src/misc/index.ts +++ b/packages/vue-composable/src/misc/index.ts @@ -2,3 +2,4 @@ export * from "./matchMedia"; export * from "./sharedRef"; export * from "./vmodel"; export * from "./injectFactory"; +export * from "./undo"; diff --git a/packages/vue-composable/src/misc/undo.ts b/packages/vue-composable/src/misc/undo.ts new file mode 100644 index 000000000..7667ede76 --- /dev/null +++ b/packages/vue-composable/src/misc/undo.ts @@ -0,0 +1,66 @@ +import { ref, computed, watch } from "../api"; +import { RefTyped, MAX_ARRAY_SIZE, wrap } from "../utils"; + +export interface UndoOptions { + deep: boolean; + + maxLength: number; + + clone: (entry: T) => T; +} + +export function useUndo( + defaultValue: RefTyped, + options?: Partial> +) { + const current = wrap(defaultValue); + + const timeline = ref([]); + const position = ref(0); + + const maxLen = (options && options.maxLength) || MAX_ARRAY_SIZE; + const clone = (options && options.clone) || ((t: any) => t); + + watch( + current, + (c, p) => { + if (position.value !== 0) { + if (timeline.value[position.value] === current.value) { + //ignore because is the same value + return; + } + // new value added + timeline.value.splice(position.value); + // reset position + position.value = 0; + } + + timeline.value.unshift(clone(p)); + if (timeline.value.length >= maxLen) { + timeline.value.pop(); + } + }, + { + ...options, + immediate: false, + flush: "sync" + } + ); + + const undo = () => (position.value = Math.max(0, position.value - 1)); + const redo = () => + (position.value = Math.min(timeline.value.length, position.value - 1)); + + const prev = computed(() => timeline.value.slice(position.value)); + const next = computed(() => timeline.value.slice(0, position.value)); + + return { + value: current, + + undo, + redo, + + prev, + next + }; +} diff --git a/packages/vue-composable/src/utils.ts b/packages/vue-composable/src/utils.ts index cd96f4d9c..ed406bf10 100644 --- a/packages/vue-composable/src/utils.ts +++ b/packages/vue-composable/src/utils.ts @@ -55,6 +55,8 @@ export function promisedTimeout(timeout: number): Promise { }); } +export const MAX_ARRAY_SIZE = 2 ** 32 - 2; + export function minMax(val: number, min: number, max: number) { if (val < min) return min; if (val > max) return max; From 7aac56e7947257fb1927bdcfa1732456eb8e4ee5 Mon Sep 17 00:00:00 2001 From: Carlos Rodrigues Date: Fri, 5 Jun 2020 08:16:17 +0100 Subject: [PATCH 2/7] feat(useUndo): add `useUndo` composable --- .../__tests__/misc/undo.spec.ts | 26 +++++++++++ packages/vue-composable/src/misc/undo.ts | 46 +++++++++++++------ 2 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 packages/vue-composable/__tests__/misc/undo.spec.ts diff --git a/packages/vue-composable/__tests__/misc/undo.spec.ts b/packages/vue-composable/__tests__/misc/undo.spec.ts new file mode 100644 index 000000000..915538393 --- /dev/null +++ b/packages/vue-composable/__tests__/misc/undo.spec.ts @@ -0,0 +1,26 @@ +import { useUndo } from "../../src"; +import { ref } from "vue3"; +describe("undo", () => { + it("should work", () => { + const v = ref(0); + + const undo = useUndo(v); + + expect(undo.value).toBe(v); + + v.value = 1; + expect(undo.prev.value).toHaveLength(1); + + v.value++; + expect(undo.prev.value).toHaveLength(2); + + undo.undo(); + expect(v.value).toBe(1); + expect(undo.prev.value).toHaveLength(2); + expect(undo.next.value).toHaveLength(1); + + undo.jump(0); + expect(undo.prev.value).toHaveLength(2); + expect(undo.next.value).toHaveLength(0); + }); +}); diff --git a/packages/vue-composable/src/misc/undo.ts b/packages/vue-composable/src/misc/undo.ts index 7667ede76..a0300120b 100644 --- a/packages/vue-composable/src/misc/undo.ts +++ b/packages/vue-composable/src/misc/undo.ts @@ -23,42 +23,60 @@ export function useUndo( watch( current, - (c, p) => { - if (position.value !== 0) { - if (timeline.value[position.value] === current.value) { - //ignore because is the same value - return; - } - // new value added + c => { + if (timeline.value[position.value] === c) { + //ignore because is the same value + return; + } + + // new value added + if (position.value > 0) { timeline.value.splice(position.value); // reset position position.value = 0; } - timeline.value.unshift(clone(p)); + // timeline.value.unshift(clone(p)); + timeline.value.unshift(clone(c)); if (timeline.value.length >= maxLen) { timeline.value.pop(); } }, { ...options, - immediate: false, + immediate: true, flush: "sync" } ); - const undo = () => (position.value = Math.max(0, position.value - 1)); - const redo = () => - (position.value = Math.min(timeline.value.length, position.value - 1)); + const undo = () => { + position.value = Math.min(timeline.value.length, position.value + 1); + current.value = timeline.value[position.value]; + }; + const redo = () => { + position.value = Math.max(0, position.value - 1); + current.value = timeline.value[position.value]; + }; + const jump = (pos: number) => (position.value = pos); - const prev = computed(() => timeline.value.slice(position.value)); - const next = computed(() => timeline.value.slice(0, position.value)); + const prev = computed(() => { + // hide current + const p = position.value === 0 ? 1 : position.value; + return timeline.value.slice(p); + }); + const next = computed(() => { + // hide current + const p = position.value === 0 ? 1 : 0; + return timeline.value.slice(p, position.value); + }); return { value: current, + timeline, undo, redo, + jump, prev, next From 0b0a37d68fcba757e6e9eab1b3710beb06da2562 Mon Sep 17 00:00:00 2001 From: Carlos Rodrigues Date: Sat, 6 Jun 2020 12:00:53 +0100 Subject: [PATCH 3/7] chore: improve test --- .../__tests__/misc/undo.spec.ts | 18 +++++++++++- packages/vue-composable/package.json | 2 +- packages/vue-composable/src/misc/undo.ts | 29 +++++++++++++------ 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/packages/vue-composable/__tests__/misc/undo.spec.ts b/packages/vue-composable/__tests__/misc/undo.spec.ts index 915538393..87ec8054f 100644 --- a/packages/vue-composable/__tests__/misc/undo.spec.ts +++ b/packages/vue-composable/__tests__/misc/undo.spec.ts @@ -19,8 +19,24 @@ describe("undo", () => { expect(undo.prev.value).toHaveLength(2); expect(undo.next.value).toHaveLength(1); - undo.jump(0); + undo.jump(-1); expect(undo.prev.value).toHaveLength(2); expect(undo.next.value).toHaveLength(0); + + const x = 10; + for (let i = 0; i < x; ++i) { + v.value = i; + } + expect(undo.prev.value).toHaveLength(2 + x); + expect(undo.next.value).toHaveLength(0); + + undo.jump(x); + + expect(undo.prev.value).toHaveLength(3); + expect(undo.next.value).toHaveLength(x); + + v.value = 42; + expect(undo.prev.value).toHaveLength(3); + expect(undo.next.value).toHaveLength(0); }); }); diff --git a/packages/vue-composable/package.json b/packages/vue-composable/package.json index f05574889..7e39d109e 100644 --- a/packages/vue-composable/package.json +++ b/packages/vue-composable/package.json @@ -46,4 +46,4 @@ "@vue/composition-api": "^0.5.0", "vue": "^2.6.10" } -} \ No newline at end of file +} diff --git a/packages/vue-composable/src/misc/undo.ts b/packages/vue-composable/src/misc/undo.ts index a0300120b..6039ac5cd 100644 --- a/packages/vue-composable/src/misc/undo.ts +++ b/packages/vue-composable/src/misc/undo.ts @@ -31,12 +31,12 @@ export function useUndo( // new value added if (position.value > 0) { - timeline.value.splice(position.value); + const pos = position.value; + timeline.value.splice(0, pos); // reset position position.value = 0; } - // timeline.value.unshift(clone(p)); timeline.value.unshift(clone(c)); if (timeline.value.length >= maxLen) { timeline.value.pop(); @@ -49,15 +49,26 @@ export function useUndo( } ); - const undo = () => { - position.value = Math.min(timeline.value.length, position.value + 1); - current.value = timeline.value[position.value]; - }; - const redo = () => { - position.value = Math.max(0, position.value - 1); + // const undo = () => { + // position.value = Math.min(timeline.value.length, position.value + 1); + // current.value = timeline.value[position.value]; + // }; + // const redo = () => { + // position.value = Math.max(0, position.value - 1); + // current.value = timeline.value[position.value]; + // }; + const undo = () => jump(1); + const redo = () => jump(-1); + + const jump = (delta: number) => { + const s = + Math.sign(delta) <= 0 + ? Math.max(delta, -next.value.length) + : Math.min(delta, prev.value.length); + + position.value += s; current.value = timeline.value[position.value]; }; - const jump = (pos: number) => (position.value = pos); const prev = computed(() => { // hide current From 0274ef545fdddb626d03f129dcc1dcd12fb3d48c Mon Sep 17 00:00:00 2001 From: Carlos Rodrigues Date: Sat, 6 Jun 2020 16:29:18 +0100 Subject: [PATCH 4/7] chore: improve tests --- .../__tests__/misc/undo.spec.ts | 30 +++++++++++- packages/vue-composable/src/misc/undo.ts | 48 ++++++++++++------- 2 files changed, 60 insertions(+), 18 deletions(-) diff --git a/packages/vue-composable/__tests__/misc/undo.spec.ts b/packages/vue-composable/__tests__/misc/undo.spec.ts index 87ec8054f..480af8963 100644 --- a/packages/vue-composable/__tests__/misc/undo.spec.ts +++ b/packages/vue-composable/__tests__/misc/undo.spec.ts @@ -1,5 +1,5 @@ import { useUndo } from "../../src"; -import { ref } from "vue3"; +import { ref } from "../../src/api"; describe("undo", () => { it("should work", () => { const v = ref(0); @@ -19,7 +19,7 @@ describe("undo", () => { expect(undo.prev.value).toHaveLength(2); expect(undo.next.value).toHaveLength(1); - undo.jump(-1); + undo.redo(); expect(undo.prev.value).toHaveLength(2); expect(undo.next.value).toHaveLength(0); @@ -39,4 +39,30 @@ describe("undo", () => { expect(undo.prev.value).toHaveLength(3); expect(undo.next.value).toHaveLength(0); }); + + it("should only store maxItems", () => { + const undo = useUndo(1, { maxLength: 2 }); + + undo.value.value++; + expect(undo.prev.value).toStrictEqual([1]); + + undo.value.value++; + expect(undo.prev.value).toStrictEqual([2, 1]); + + undo.value.value++; + expect(undo.prev.value).toStrictEqual([3, 2]); + + undo.value.value++; + expect(undo.prev.value).toStrictEqual([4, 3]); + }); + + it("should use clone function", () => { + const clone = jest.fn() as any; + const undo = useUndo({ a: 1 }, { clone }); + + expect(clone).toHaveBeenCalled(); + + undo.value.value = { a: 2 }; + expect(clone).toHaveBeenCalledTimes(2); + }); }); diff --git a/packages/vue-composable/src/misc/undo.ts b/packages/vue-composable/src/misc/undo.ts index 6039ac5cd..018051474 100644 --- a/packages/vue-composable/src/misc/undo.ts +++ b/packages/vue-composable/src/misc/undo.ts @@ -1,4 +1,4 @@ -import { ref, computed, watch } from "../api"; +import { ref, computed, watch, Ref, ComputedRef } from "../api"; import { RefTyped, MAX_ARRAY_SIZE, wrap } from "../utils"; export interface UndoOptions { @@ -9,11 +9,35 @@ export interface UndoOptions { clone: (entry: T) => T; } +export interface UndoOperation { + (step: number): void; + (): void; +} + +export interface UndoReturn { + value: Ref; + + undo: UndoOperation; + redo: UndoOperation; + + jump: (delta: number) => void; + + prev: ComputedRef; + next: ComputedRef; +} + +export function useUndo(): UndoReturn; + export function useUndo( defaultValue: RefTyped, options?: Partial> -) { - const current = wrap(defaultValue); +): UndoReturn; + +export function useUndo( + defaultValue?: RefTyped, + options?: Partial> +): UndoReturn { + const current = wrap(defaultValue!); const timeline = ref([]); const position = ref(0); @@ -37,10 +61,11 @@ export function useUndo( position.value = 0; } - timeline.value.unshift(clone(c)); - if (timeline.value.length >= maxLen) { + if (timeline.value.length > maxLen) { timeline.value.pop(); } + + timeline.value.unshift(clone(c)); }, { ...options, @@ -49,16 +74,8 @@ export function useUndo( } ); - // const undo = () => { - // position.value = Math.min(timeline.value.length, position.value + 1); - // current.value = timeline.value[position.value]; - // }; - // const redo = () => { - // position.value = Math.max(0, position.value - 1); - // current.value = timeline.value[position.value]; - // }; - const undo = () => jump(1); - const redo = () => jump(-1); + const undo = (step = 1) => jump(step); + const redo = (step = 1) => jump(-step); const jump = (delta: number) => { const s = @@ -83,7 +100,6 @@ export function useUndo( return { value: current, - timeline, undo, redo, From 07b7190a52dc0fe54025d66e941239867a20e9c4 Mon Sep 17 00:00:00 2001 From: Carlos Rodrigues Date: Sat, 6 Jun 2020 21:48:05 +0100 Subject: [PATCH 5/7] chore: add docs --- docs/.vuepress/components/UndoExample.vue | 30 ++++++ docs/.vuepress/config.js | 1 + docs/README.md | 1 + docs/api/vue-composable.api.md | 37 +++++++ docs/composable/misc/undo.md | 118 ++++++++++++++++++++++ packages/axios/package.json | 2 +- packages/vue-composable/README.md | 1 + packages/vue-composable/src/misc/undo.ts | 61 ++++++++++- packages/vue-composable/src/utils.ts | 1 + readme.md | 1 + 10 files changed, 247 insertions(+), 6 deletions(-) create mode 100644 docs/.vuepress/components/UndoExample.vue create mode 100644 docs/composable/misc/undo.md diff --git a/docs/.vuepress/components/UndoExample.vue b/docs/.vuepress/components/UndoExample.vue new file mode 100644 index 000000000..381985518 --- /dev/null +++ b/docs/.vuepress/components/UndoExample.vue @@ -0,0 +1,30 @@ + + + diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index d7b80dc22..a8281b25b 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -132,6 +132,7 @@ module.exports = { children: [ ["composable/misc/sharedRef", "SharedRef"], ["composable/misc/vmodel", "vModel"], + ["composable/misc/undo", "Undo"], ["composable/misc/injectFactory", "injectFactory"] ] }, diff --git a/docs/README.md b/docs/README.md index 3ffcc5a61..470aa36df 100644 --- a/docs/README.md +++ b/docs/README.md @@ -74,6 +74,7 @@ Check out the [examples folder](examples) or start hacking on [codesandbox](http - [sharedRef](https://pikax.me/vue-composable/composable/misc/sharedRef) - cross-tab reactive `ref` - [VModel](https://pikax.me/vue-composable/composable/misc/vmodel) - helper to wrap model update into a `ref` `[vue3 only]` +- [Undo](https://pikax.me/vue-composable/composable/meta/undo) - Tracks variable history, to allow `undo` and `redo` - [injectFactory](https://pikax.me/vue-composable/composable/misc/injectFactory) - same as [inject](https://vue-composition-api-rfc.netlify.app/api.html#dependency-injection) but allows you to have a factory as default value ### Storage diff --git a/docs/api/vue-composable.api.md b/docs/api/vue-composable.api.md index 939360ee6..eb4e3ae99 100644 --- a/docs/api/vue-composable.api.md +++ b/docs/api/vue-composable.api.md @@ -534,6 +534,9 @@ export interface LocalStorageReturn { // @public (undocumented) export type LocalStorageTyped = string; +// @public (undocumented) +export const MAX_ARRAY_SIZE: number; + // @public (undocumented) export function minMax(val: number, min: number, max: number): number; @@ -896,6 +899,31 @@ export interface StorageSerializer { stringify(item: T): string; } +// @public (undocumented) +export interface UndoOperation { + (step: number): void; + (): void; +} + +// @public (undocumented) +export interface UndoOptions { + clone: (entry: T) => T; + deep: boolean; + maxLength: number; +} + +// @public (undocumented) +export interface UndoReturn { + jump(delta: number): void; + next: ComputedRef; + prev: ComputedRef; + redo(): void; + redo(step: number): void; + undo(): void; + undo(step: number): void; + value: Ref; +} + // @public (undocumented) export function unwrap(o: RefTyped): T; @@ -1617,6 +1645,15 @@ export function useStorage( // @public (undocumented) export function useTitle(overrideTitle?: string | null): Ref; +// @public (undocumented) +export function useUndo(): UndoReturn; + +// @public (undocumented) +export function useUndo( + defaultValue: RefTyped, + options?: Partial> +): UndoReturn; + // Warning: (ae-forgotten-export) The symbol "UseValidation" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ValidationOutput" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ValidationGroupResult" needs to be exported by the entry point index.d.ts diff --git a/docs/composable/misc/undo.md b/docs/composable/misc/undo.md new file mode 100644 index 000000000..6ae1f8072 --- /dev/null +++ b/docs/composable/misc/undo.md @@ -0,0 +1,118 @@ +# Undo + +> Tracks variable history, to allow `undo` and `redo` + +## Parameters + +```js +import { useUndo } from "vue-composable"; + +export interface UndoOptions { + /** + * Watch `deep` option for changes + */ + deep: boolean; + + /** + * Max history change + * @default MAX_ARRAY_SIZE + */ + maxLength: number; + + /** + * Clone strategy + * @default (x)=>x + */ + clone: (entry: T) => T; +} + +const defaultOptions = { + deep: undefined, + + + maxLength: MAX_ARRAY_SIZE, + + clone(x) { + return x; + } +} + + +useUndo(defaultValue?, options?); +``` + +| Parameters | Type | Required | Default | Description | +| ------------ | ----------- | -------- | ---------------- | --------------------- | +| defaultValue | `Ref|T` | `false` | `undefined` | Default value | +| options | `(x: T)=>T` | `false` | `defaultOptions` | Configuration options | + +## State + +The `useUndo` function exposes the following reactive state: + +```js +import { useUndo } from "vue-composable"; + +const { value, prev, next } = useUndo(); +``` + +| State | Type | Description | +| ----- | ---------- | ------------------------------------------ | +| value | `Ref` | State value | +| prev | `Ref` | Array of prev states | +| next | `Ref` | Array of next states, only if you `undo()` | + +## Methods + +The `useUndo` function exposes the following methods: + +```js +import { useUndo } from "vue-composable"; + +const { jump, undo, redo } = useUndo(); +``` + +| Signature | Description | +| ------------- | -------------------------------------------------------------------------------------------- | +| `jump(delta)` | moves the cursor to `delta`, if delta is positive it will `undo`, if negative it will `redo` | +| `undo(n?)` | Undo the state to `n` default to 1 | +| `redo(n?)` | Redo the state to `n` default to 1 | + +## Example + + + +### Code + +```vue + + + +``` diff --git a/packages/axios/package.json b/packages/axios/package.json index f5ad4f488..b3efc2725 100644 --- a/packages/axios/package.json +++ b/packages/axios/package.json @@ -58,4 +58,4 @@ "@vue/runtime-core": "^3.0.0-beta.14", "typescript": "^3.8.3" } -} \ No newline at end of file +} diff --git a/packages/vue-composable/README.md b/packages/vue-composable/README.md index 5cfc0612f..cc3e794b8 100644 --- a/packages/vue-composable/README.md +++ b/packages/vue-composable/README.md @@ -77,6 +77,7 @@ Check our [documentation](https://pikax.me/vue-composable/) - [sharedRef](https://pikax.me/vue-composable/composable/misc/sharedRef) - cross-tab reactive `ref` - [VModel](https://pikax.me/vue-composable/composable/meta/vmodel) - helper to wrap model update into a `ref` `[vue3 only]` +- [Undo](https://pikax.me/vue-composable/composable/meta/undo) - Tracks variable history, to allow `undo` and `redo` - [injectFactory](https://pikax.me/vue-composable/composable/misc/injectFactory) - same as [inject](https://vue-composition-api-rfc.netlify.app/api.html#dependency-injection) but allows you to have a factory as default value ### Storage diff --git a/packages/vue-composable/src/misc/undo.ts b/packages/vue-composable/src/misc/undo.ts index 018051474..80661fac7 100644 --- a/packages/vue-composable/src/misc/undo.ts +++ b/packages/vue-composable/src/misc/undo.ts @@ -2,27 +2,78 @@ import { ref, computed, watch, Ref, ComputedRef } from "../api"; import { RefTyped, MAX_ARRAY_SIZE, wrap } from "../utils"; export interface UndoOptions { + /** + * Watch `deep` option for changes + */ deep: boolean; + /** + * Max history change + * @default MAX_ARRAY_SIZE + * + */ maxLength: number; + /** + * Clone strategy + * @default (x)=>x + */ clone: (entry: T) => T; } export interface UndoOperation { + /** + * Move state + * @param step - Positive position + */ (step: number): void; + /** + * Move 1 step in history + */ (): void; } export interface UndoReturn { + /** + * Current value + */ value: Ref; - undo: UndoOperation; - redo: UndoOperation; - - jump: (delta: number) => void; - + /** + * Undo state to the previous + */ + undo(): void; + + /** + * Undo state + * @param step - Positive position + */ + undo(step: number): void; + + /** + * Redo state to the previous + */ + redo(): void; + /** + * Redo state + * @param step - Positive position + */ + redo(step: number): void; + + /** + * Moves the cursor to delta + * @param delta - If positive it will `undo` the state, if negative it will `redo` + */ + jump(delta: number): void; + + /** + * List of previous states + */ prev: ComputedRef; + /** + * List of next states + * This is only populated if you `undo` or `jump` + */ next: ComputedRef; } diff --git a/packages/vue-composable/src/utils.ts b/packages/vue-composable/src/utils.ts index ed406bf10..39278592b 100644 --- a/packages/vue-composable/src/utils.ts +++ b/packages/vue-composable/src/utils.ts @@ -55,6 +55,7 @@ export function promisedTimeout(timeout: number): Promise { }); } +// https://v8.dev/blog/react-cliff export const MAX_ARRAY_SIZE = 2 ** 32 - 2; export function minMax(val: number, min: number, max: number) { diff --git a/readme.md b/readme.md index 5cfc0612f..cc3e794b8 100644 --- a/readme.md +++ b/readme.md @@ -77,6 +77,7 @@ Check our [documentation](https://pikax.me/vue-composable/) - [sharedRef](https://pikax.me/vue-composable/composable/misc/sharedRef) - cross-tab reactive `ref` - [VModel](https://pikax.me/vue-composable/composable/meta/vmodel) - helper to wrap model update into a `ref` `[vue3 only]` +- [Undo](https://pikax.me/vue-composable/composable/meta/undo) - Tracks variable history, to allow `undo` and `redo` - [injectFactory](https://pikax.me/vue-composable/composable/misc/injectFactory) - same as [inject](https://vue-composition-api-rfc.netlify.app/api.html#dependency-injection) but allows you to have a factory as default value ### Storage From e1406cab5a0e155831a0e5c51ac0ae63192e6b39 Mon Sep 17 00:00:00 2001 From: Carlos Rodrigues Date: Sun, 7 Jun 2020 08:09:57 +0100 Subject: [PATCH 6/7] chore: move to state --- docs/.vuepress/config.js | 7 ++++++- docs/README.md | 5 ++++- packages/vue-composable/README.md | 5 ++++- .../vue-composable/__tests__/{misc => state}/undo.spec.ts | 0 packages/vue-composable/src/index.ts | 2 ++ packages/vue-composable/src/misc/index.ts | 1 - packages/vue-composable/src/state/index.ts | 1 + packages/vue-composable/src/{misc => state}/undo.ts | 0 readme.md | 5 ++++- 9 files changed, 21 insertions(+), 5 deletions(-) rename packages/vue-composable/__tests__/{misc => state}/undo.spec.ts (100%) create mode 100644 packages/vue-composable/src/state/index.ts rename packages/vue-composable/src/{misc => state}/undo.ts (100%) diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index a8281b25b..fc47c189d 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -132,7 +132,6 @@ module.exports = { children: [ ["composable/misc/sharedRef", "SharedRef"], ["composable/misc/vmodel", "vModel"], - ["composable/misc/undo", "Undo"], ["composable/misc/injectFactory", "injectFactory"] ] }, @@ -214,6 +213,12 @@ module.exports = { collapsable: false, children: [["composable/meta/title", "Title"]] }, + { + title: "state", + sidebarDepth: 1, + collapsable: false, + children: [["composable/misc/undo", "Undo"]] + }, { title: "External", sidebarDepth: 1, diff --git a/docs/README.md b/docs/README.md index 470aa36df..e1c32451f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -74,7 +74,6 @@ Check out the [examples folder](examples) or start hacking on [codesandbox](http - [sharedRef](https://pikax.me/vue-composable/composable/misc/sharedRef) - cross-tab reactive `ref` - [VModel](https://pikax.me/vue-composable/composable/misc/vmodel) - helper to wrap model update into a `ref` `[vue3 only]` -- [Undo](https://pikax.me/vue-composable/composable/meta/undo) - Tracks variable history, to allow `undo` and `redo` - [injectFactory](https://pikax.me/vue-composable/composable/misc/injectFactory) - same as [inject](https://vue-composition-api-rfc.netlify.app/api.html#dependency-injection) but allows you to have a factory as default value ### Storage @@ -113,6 +112,10 @@ Check out the [examples folder](examples) or start hacking on [codesandbox](http - [Title](https://pikax.me/vue-composable/composable/meta/title) - reactive `document.title` +### State + +- [Undo](https://pikax.me/vue-composable/composable/meta/undo) - Tracks variable history, to allow `undo` and `redo` + ### Web - [Fetch](https://pikax.me/vue-composable/composable/web/fetch) - reactive `fetch` wrapper diff --git a/packages/vue-composable/README.md b/packages/vue-composable/README.md index cc3e794b8..86732412a 100644 --- a/packages/vue-composable/README.md +++ b/packages/vue-composable/README.md @@ -77,7 +77,6 @@ Check our [documentation](https://pikax.me/vue-composable/) - [sharedRef](https://pikax.me/vue-composable/composable/misc/sharedRef) - cross-tab reactive `ref` - [VModel](https://pikax.me/vue-composable/composable/meta/vmodel) - helper to wrap model update into a `ref` `[vue3 only]` -- [Undo](https://pikax.me/vue-composable/composable/meta/undo) - Tracks variable history, to allow `undo` and `redo` - [injectFactory](https://pikax.me/vue-composable/composable/misc/injectFactory) - same as [inject](https://vue-composition-api-rfc.netlify.app/api.html#dependency-injection) but allows you to have a factory as default value ### Storage @@ -116,6 +115,10 @@ Check our [documentation](https://pikax.me/vue-composable/) - [Title](https://pikax.me/vue-composable/composable/meta/title) - reactive `document.title` +### State + +- [Undo](https://pikax.me/vue-composable/composable/meta/undo) - Tracks variable history, to allow `undo` and `redo` + ### Web - [Fetch](https://pikax.me/vue-composable/composable/web/fetch) - reactive `fetch` wrapper diff --git a/packages/vue-composable/__tests__/misc/undo.spec.ts b/packages/vue-composable/__tests__/state/undo.spec.ts similarity index 100% rename from packages/vue-composable/__tests__/misc/undo.spec.ts rename to packages/vue-composable/__tests__/state/undo.spec.ts diff --git a/packages/vue-composable/src/index.ts b/packages/vue-composable/src/index.ts index 4ee094af8..125e2d41e 100644 --- a/packages/vue-composable/src/index.ts +++ b/packages/vue-composable/src/index.ts @@ -14,7 +14,9 @@ export * from "./validation"; export * from "./i18n"; export * from "./meta"; export * from "./ssr"; +export * from "./state"; export const VERSION = __VERSION__; +// istanbul ignore next export const VUE_VERSION: "2" | "3" = __VUE_2__ ? "2" : "3"; export const COMMIT = __COMMIT__; diff --git a/packages/vue-composable/src/misc/index.ts b/packages/vue-composable/src/misc/index.ts index 1f3b11fcd..021d5021c 100644 --- a/packages/vue-composable/src/misc/index.ts +++ b/packages/vue-composable/src/misc/index.ts @@ -2,4 +2,3 @@ export * from "./matchMedia"; export * from "./sharedRef"; export * from "./vmodel"; export * from "./injectFactory"; -export * from "./undo"; diff --git a/packages/vue-composable/src/state/index.ts b/packages/vue-composable/src/state/index.ts new file mode 100644 index 000000000..dad0cc440 --- /dev/null +++ b/packages/vue-composable/src/state/index.ts @@ -0,0 +1 @@ +export * from "./undo"; diff --git a/packages/vue-composable/src/misc/undo.ts b/packages/vue-composable/src/state/undo.ts similarity index 100% rename from packages/vue-composable/src/misc/undo.ts rename to packages/vue-composable/src/state/undo.ts diff --git a/readme.md b/readme.md index cc3e794b8..86732412a 100644 --- a/readme.md +++ b/readme.md @@ -77,7 +77,6 @@ Check our [documentation](https://pikax.me/vue-composable/) - [sharedRef](https://pikax.me/vue-composable/composable/misc/sharedRef) - cross-tab reactive `ref` - [VModel](https://pikax.me/vue-composable/composable/meta/vmodel) - helper to wrap model update into a `ref` `[vue3 only]` -- [Undo](https://pikax.me/vue-composable/composable/meta/undo) - Tracks variable history, to allow `undo` and `redo` - [injectFactory](https://pikax.me/vue-composable/composable/misc/injectFactory) - same as [inject](https://vue-composition-api-rfc.netlify.app/api.html#dependency-injection) but allows you to have a factory as default value ### Storage @@ -116,6 +115,10 @@ Check our [documentation](https://pikax.me/vue-composable/) - [Title](https://pikax.me/vue-composable/composable/meta/title) - reactive `document.title` +### State + +- [Undo](https://pikax.me/vue-composable/composable/meta/undo) - Tracks variable history, to allow `undo` and `redo` + ### Web - [Fetch](https://pikax.me/vue-composable/composable/web/fetch) - reactive `fetch` wrapper From 0444b8e8104254bef1a85368118bf88819bc4c49 Mon Sep 17 00:00:00 2001 From: Carlos Rodrigues Date: Sat, 13 Jun 2020 09:35:56 +0100 Subject: [PATCH 7/7] chore: update docs and link --- docs/.vuepress/config.js | 2 +- docs/README.md | 2 +- docs/composable/{misc => state}/undo.md | 0 packages/vue-composable/README.md | 2 +- readme.md | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) rename docs/composable/{misc => state}/undo.md (100%) diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index fc47c189d..3dec5d0cf 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -217,7 +217,7 @@ module.exports = { title: "state", sidebarDepth: 1, collapsable: false, - children: [["composable/misc/undo", "Undo"]] + children: [["composable/state/undo", "Undo"]] }, { title: "External", diff --git a/docs/README.md b/docs/README.md index e1c32451f..287e57357 100644 --- a/docs/README.md +++ b/docs/README.md @@ -114,7 +114,7 @@ Check out the [examples folder](examples) or start hacking on [codesandbox](http ### State -- [Undo](https://pikax.me/vue-composable/composable/meta/undo) - Tracks variable history, to allow `undo` and `redo` +- [Undo](https://pikax.me/vue-composable/composable/state/undo) - Tracks variable history, to allow `undo` and `redo` ### Web diff --git a/docs/composable/misc/undo.md b/docs/composable/state/undo.md similarity index 100% rename from docs/composable/misc/undo.md rename to docs/composable/state/undo.md diff --git a/packages/vue-composable/README.md b/packages/vue-composable/README.md index 86732412a..281ed62d8 100644 --- a/packages/vue-composable/README.md +++ b/packages/vue-composable/README.md @@ -117,7 +117,7 @@ Check our [documentation](https://pikax.me/vue-composable/) ### State -- [Undo](https://pikax.me/vue-composable/composable/meta/undo) - Tracks variable history, to allow `undo` and `redo` +- [Undo](https://pikax.me/vue-composable/composable/state/undo) - Tracks variable history, to allow `undo` and `redo` ### Web diff --git a/readme.md b/readme.md index 86732412a..281ed62d8 100644 --- a/readme.md +++ b/readme.md @@ -117,7 +117,7 @@ Check our [documentation](https://pikax.me/vue-composable/) ### State -- [Undo](https://pikax.me/vue-composable/composable/meta/undo) - Tracks variable history, to allow `undo` and `redo` +- [Undo](https://pikax.me/vue-composable/composable/state/undo) - Tracks variable history, to allow `undo` and `redo` ### Web