Skip to content

Commit

Permalink
Added ego behavior to useVingRecord() and useVingKind() to allow disa…
Browse files Browse the repository at this point in the history
…mbiguation of multiple copies of the same record with different views.
  • Loading branch information
rizen committed Oct 27, 2024
1 parent 5595c79 commit 46abcae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
15 changes: 15 additions & 0 deletions app/composables/ving/useVingKind.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ class VingKind {
const self = this;
return useVingRecord({
...params,
ego: self.#behavior.ego,
query: self.query,
createApi: self.getCreateApi(),
onCreate: self.#behavior.onCreate,
Expand Down Expand Up @@ -510,6 +511,20 @@ class VingKind {
* Creates an instance of VingKind in the form of a composable
*
* @param {object} behavior An object that defines the behavior of the kind
* @param {boolean} behavior.unshift If true, new records will be added to the beginning of the list instead of the end.
* @param {boolean} behavior.suppressErrorNotifications If true, errors will not be displayed to the user.
* @param {object} behavior.query An object containing query parameters to send when interacting with endpoints for this kind.
* @param {object} behavior.newDefaults An object containing default values for new records.
* @param {function} behavior.onCreate A callback function that will be called when a new record is created.
* @param {function} behavior.onUpdate A callback function that will be called when a record is updated.
* @param {function} behavior.onDelete A callback function that will be called when a record is deleted.
* @param {function} behavior.onSearch A callback function that will be called when a search is performed.
* @param {function} behavior.onAllDone A callback function that will be called when all the requests have been processed.
* @param {function} behavior.onEach A callback function that will be called for each record fetched.
* @param {string} behavior.createApi The endpoint for creating records.
* @param {string} behavior.listApi The endpoint for fetching the list of records.
* @param {string} behavior.optionsApi The endpoint for fetching the enumerated props options.
* @param {string} behavior.ego An optional string that will be prepended to the id of fetched records in Pinia so that they can be distinguished from other instances of the same record. Useful if you're loading multiple instances of the same object on the same page.
* @returns {object} A VingKind instance
*/
export const useVingKind = (behavior = {}) => {
Expand Down
4 changes: 2 additions & 2 deletions app/composables/ving/useVingRecord.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { isObject, isUndefined } from '#ving/utils/identify.mjs';
* @param {object} behavior.links - Any default link objects. Defaults to `{}`. Usually no reason to ever specify this.
* @param {object} behavior.related - Any default related objects. Defaults to `{}`. Usually no reason to ever specify this.
* @param {object[]} behavior.warnings - An array of warning objects. Defaults to `[]`. Usually no reason to ever specify this.
* @param {string} behavior.ego An optional string that will be prepended to the id of fetched records in Pinia so that they can be distinguished from other instances of the same record. Useful if you're loading multiple instances of the same object on the same page.
* @returns {VingRecordStore} - A Pinia store.
* @example
* const user = useVingRecord({
Expand All @@ -42,8 +43,7 @@ import { isObject, isUndefined } from '#ving/utils/identify.mjs';

export default (behavior) => {
const notify = useNotify();

const generate = defineStore(behavior.id || v4(), {
const generate = defineStore(behavior.id ? (behavior.ego ? behavior.ego + '-' + behavior.id : behavior.id) : v4(), {
state: () => ({
props: behavior.props || {},
meta: behavior.meta || {},
Expand Down
3 changes: 3 additions & 0 deletions ving/docs/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ outline: deep

## October 2024

### 2024-10-27
* Added ego behavior to useVingRecord() and useVingKind() to allow disambiguation of multiple copies of the same record with different views.

### 2024-10-25
* Fix a bug in redis client where it wouldn't connect to the AWS valkey/redis cluster.
* Fix a hydration mismatch in form inputs subtext.
Expand Down

0 comments on commit 46abcae

Please sign in to comment.