quasar-ui-danx 0.4.15 → 0.4.16

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quasar-ui-danx",
3
- "version": "0.4.15",
3
+ "version": "0.4.16",
4
4
  "author": "Dan <dan@flytedesk.com>",
5
5
  "description": "DanX Vue / Quasar component library",
6
6
  "license": "MIT",
@@ -14,6 +14,25 @@ export const activeActionVnode: Ref = shallowRef(null);
14
14
  export function useActions(actions: ActionOptions[], globalOptions: Partial<ActionOptions> | null = null) {
15
15
  const namespace = uid();
16
16
 
17
+ /**
18
+ * Extend an action so the base action can be modified without affecting other places the action is used.
19
+ * This isolates the action to the provided id, so it is still re-usable across the system, but does not affect behavior elsewhere.
20
+ *
21
+ * For example, when you have a list of items and you want to perform a callback on the action on a single item, you can extend the action
22
+ * with the id of the item you want to perform the action on, allowing you to perform behavior on a single item, instead of all instances
23
+ * in the list receiving the same callback.
24
+ */
25
+ function extendAction(actionName: string, extendedId: string | number, actionOptions: Partial<ActionOptions>): ResourceAction {
26
+ const action = getAction(actionName);
27
+ const extendedAction = { ...action, ...actionOptions, id: extendedId };
28
+ if (extendedAction.debounce) {
29
+ extendedAction.trigger = useDebounceFn((target, input) => performAction(extendedAction, target, input), extendedAction.debounce);
30
+ } else {
31
+ extendedAction.trigger = (target, input) => performAction(extendedAction, target, input);
32
+ }
33
+ return storeObject(extendedAction);
34
+ }
35
+
17
36
  /**
18
37
  * Resolve the action object based on the provided name (or return the object if the name is already an object)
19
38
  */
@@ -140,7 +159,8 @@ export function useActions(actions: ActionOptions[], globalOptions: Partial<Acti
140
159
 
141
160
  return {
142
161
  getAction,
143
- getActions
162
+ getActions,
163
+ extendAction
144
164
  };
145
165
  }
146
166
 
@@ -34,9 +34,11 @@ export function storeObject<T extends TypedObject>(newObject: T): ShallowReactiv
34
34
  // Recursively store all the children of the object as well
35
35
  for (const key of Object.keys(newObject)) {
36
36
  const value = newObject[key];
37
- if (Array.isArray(value) && value.length > 0 && typeof value[0] === "object") {
37
+ if (Array.isArray(value) && value.length > 0) {
38
38
  for (const index in value) {
39
- newObject[key][index] = storeObject(value[index]);
39
+ if (value[index] && typeof value[index] === "object") {
40
+ newObject[key][index] = storeObject(value[index]);
41
+ }
40
42
  }
41
43
  } else if (value?.__type) {
42
44
  // @ts-expect-error newObject[key] is guaranteed to be a TypedObject