From 12e20e460d9984ad55b01c203efbf69ea58915da Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Tue, 4 Aug 2020 16:31:31 +0100 Subject: [PATCH] tidyup & JSDoc --- .../builderStore/fetchBindableProperties.js | 45 ++++++++++--------- packages/builder/tests/binding.spec.js | 4 +- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/packages/builder/src/builderStore/fetchBindableProperties.js b/packages/builder/src/builderStore/fetchBindableProperties.js index 8f059bd6bd..d2d775ccad 100644 --- a/packages/builder/src/builderStore/fetchBindableProperties.js +++ b/packages/builder/src/builderStore/fetchBindableProperties.js @@ -1,27 +1,28 @@ -import { cloneDeep, difference, fill } from "lodash" +import { cloneDeep, difference } from "lodash" -const stubBindings = [ - { - // type: instance represents a bindable property of a component - type: "instance", - instance: {} /** a component instance **/, - // how the binding expression persists, and is used in the app at runtime - runtimeBinding: "state..", - // how the binding exressions looks to the user of the builder - readableBinding: "", - }, - { - type: "context", - instance: { - /** a component instance **/ - }, - // how the binding expression persists, and is used in the app at runtime - runtimeBinding: "context._parent.", - // how the binding exressions looks to the user of the builder - readableBinding: "..", - }, -] +/** + * parameter for fetchBindableProperties function + * @typedef {Object} fetchBindablePropertiesParameter + * @property {string} componentInstanceId - an _id of a component that has been added to a screen, whihc you want to fetch bindable props for + * @propperty {Object} screen - current screen - where componentInstanceId lives + * @property {Object} components - dictionary of component definitions + * @property {Array} models - array of all models + */ +/** + * + * @typedef {Object} BindableProperty + * @property {string} type - either "instance" (binding to a component instance) or "context" (binding to data in context e.g. List Item) + * @property {Object} instance - relevant component instance. If "context" type, this instance is the component that provides the context... e.g. the List + * @property {string} runtimeBinding - a binding string that is a) saved against the string, and b) used at runtime to read/write the value + * @property {string} readableBinding - a binding string that is displayed to the user, in the builder + */ + +/** + * Generates all allowed bindings from within any particular component instance + * @param {fetchBindablePropertiesParameter} param + * @returns {Array.} + */ export default function({ componentInstanceId, screen, components, models }) { const walkResult = walk({ // cloning so we are free to mutate props (e.g. by adding _contexts) diff --git a/packages/builder/tests/binding.spec.js b/packages/builder/tests/binding.spec.js index cfdbec6dbb..ac90faf9bf 100644 --- a/packages/builder/tests/binding.spec.js +++ b/packages/builder/tests/binding.spec.js @@ -89,9 +89,7 @@ describe("fetch bindable properties", () => { }) const componentBinding = result.find(r => r.instance._id === "child-list-item-input-id" && r.type === "instance") expect(componentBinding).toBeDefined() - }) - - + }) })