diff --git a/app/composables/ving/useVingKind.mjs b/app/composables/ving/useVingKind.mjs index 49fcd867..0453dff7 100644 --- a/app/composables/ving/useVingKind.mjs +++ b/app/composables/ving/useVingKind.mjs @@ -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, @@ -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 = {}) => { diff --git a/app/composables/ving/useVingRecord.mjs b/app/composables/ving/useVingRecord.mjs index 1d3c54f7..59fb0ed3 100644 --- a/app/composables/ving/useVingRecord.mjs +++ b/app/composables/ving/useVingRecord.mjs @@ -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({ @@ -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 || {}, diff --git a/ving/docs/change-log.md b/ving/docs/change-log.md index a1a9dbf9..363f337f 100644 --- a/ving/docs/change-log.md +++ b/ving/docs/change-log.md @@ -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.