feat: behavior builders
This commit is contained in:
parent
f08dfff296
commit
a034521ec0
41
packages/behavior/builders.js
Normal file
41
packages/behavior/builders.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
export function buildTraversal(path, value) {
|
||||
const traversal = {
|
||||
type: 'traversal',
|
||||
steps: path.map((key) => {
|
||||
return {
|
||||
type: 'key',
|
||||
key: key,
|
||||
};
|
||||
}),
|
||||
};
|
||||
if ('undefined' !== typeof value) {
|
||||
if ('object' === typeof value && 'traversal' === value.type) {
|
||||
traversal.value = value;
|
||||
}
|
||||
else {
|
||||
traversal.value = {
|
||||
type: 'literal',
|
||||
value,
|
||||
};
|
||||
}
|
||||
}
|
||||
return traversal;
|
||||
}
|
||||
|
||||
export const buildInvoke = (path, args) => {
|
||||
const traversal = buildTraversal(path);
|
||||
traversal.steps.push({
|
||||
type: 'invoke',
|
||||
args: args.map((arg) => {
|
||||
if ('object' === typeof arg && 'traversal' === arg.type) {
|
||||
return arg;
|
||||
}
|
||||
return {
|
||||
type: 'literal',
|
||||
value: arg,
|
||||
};
|
||||
}),
|
||||
});
|
||||
return traversal;
|
||||
}
|
||||
|
|
@ -8,3 +8,4 @@ export {
|
|||
fromJSON as behaviorItemFromJSON,
|
||||
register as registerBehaviorItem
|
||||
} from './item/registry';
|
||||
export {buildInvoke, buildTraversal} from './builders';
|
Loading…
Reference in New Issue
Block a user