@fleetbase/ember-core 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import getModelName from '@fleetbase/ember-core/utils/get-model-name';
|
|
2
|
+
import isModel from '@fleetbase/ember-core/utils/is-model';
|
|
3
|
+
import { camelize } from '@ember/string';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Applies context and dynamic arguments to a given component.
|
|
7
|
+
*
|
|
8
|
+
* @param {Component} component - The component to which context and arguments will be applied.
|
|
9
|
+
*/
|
|
10
|
+
export default function applyContextComponentArguments(component) {
|
|
11
|
+
const { context, dynamicArgs = {} } = component.args;
|
|
12
|
+
|
|
13
|
+
// Apply context model if available
|
|
14
|
+
if (context && isModel(context)) {
|
|
15
|
+
const contextModelName = camelize(getModelName(context));
|
|
16
|
+
if (contextModelName) {
|
|
17
|
+
component[contextModelName] = context;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Execute any apply callback present in dynamic arguments
|
|
22
|
+
const { applyCallback } = dynamicArgs;
|
|
23
|
+
if (typeof applyCallback === 'function') {
|
|
24
|
+
applyCallback(component);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Apply other dynamic arguments to the component
|
|
28
|
+
for (const [key, value] of Object.entries(dynamicArgs)) {
|
|
29
|
+
if (key !== 'applyCallback') {
|
|
30
|
+
component[key] = value;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default function contextComponentCallback(component, name, ...params) {
|
|
2
|
+
let callbackInvoked = false;
|
|
3
|
+
|
|
4
|
+
if (typeof component.args[name] === 'function') {
|
|
5
|
+
component.args[name](...params);
|
|
6
|
+
callbackInvoked = true;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// now do for context options
|
|
10
|
+
if (typeof component.args.options === 'object' && typeof component.args.options[name] === 'function') {
|
|
11
|
+
component.args.options[name](...params);
|
|
12
|
+
callbackInvoked = true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return callbackInvoked;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '@fleetbase/ember-core/utils/apply-context-component-arguments';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '@fleetbase/ember-core/utils/context-component-callback';
|
package/package.json
CHANGED