Skip to content

Commit

Permalink
feat: add immediate parameter to list autoload
Browse files Browse the repository at this point in the history
  • Loading branch information
ascott18 committed Sep 17, 2024
1 parent 0f3bd48 commit 4ac1791
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 11 additions & 6 deletions docs/stacks/vue/layers/viewmodels.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,19 @@ Starts auto-loading of the list as changes to its parameters occur. Loads are pe
``` ts
type AutoLoadOptions<TThis> =
{
/** Time, in milliseconds, to debounce loads for. */
wait?: number;
/** Time, in milliseconds, to debounce loads for. */
wait?: number;

/** Additional options to pass to the third parameter of lodash's `debounce` function. */
debounce?: DebounceSettings;
/** Additional options to pass to the third parameter of lodash's `debounce` function. */
debounce?: DebounceSettings;

/** A function that will be called before loading that can return false to prevent a load. */
predicate?: (viewModel: TThis) => boolean;
/** A function that will be called before loading that can return false to prevent a load. */
predicate?: (viewModel: TThis) => boolean;

/** If true, an immediate initial load of the list will be performed.
* Otherwise, the initial auto-load of the list won't occur until
* the first change to its parameters occur. */
immediate?: boolean;
}
```
Expand Down
8 changes: 8 additions & 0 deletions src/coalesce-vue/src/viewmodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,11 @@ export abstract class ListViewModel<
onChange
);
startAutoCall(this._autoLoadState, vue, watcher, enqueueLoad);

if (options.immediate) {
// Immediate load doesn't use `enqueueLoad` so that there's no delay.
this.$load();
}
}

/** Stops auto-loading if it is currently enabled. */
Expand Down Expand Up @@ -2034,6 +2039,9 @@ type DebounceOptions = {
type AutoLoadOptions<TThis> = DebounceOptions & {
/** A function that will be called before autoloading that can return false to prevent a load. */
predicate?: (viewModel: TThis) => boolean;

/** If true, an immediate initial load of the list will be performed. Otherwise, the initial auto-load of the list won't occur until the first change to its parameters occur. */
immediate?: boolean;
};

type AutoSaveOptions<TThis> = DebounceOptions &
Expand Down

0 comments on commit 4ac1791

Please sign in to comment.