forked from tsai/budibase
8 changed files with 16 additions and 95 deletions
@ -1,28 +0,0 @@ |
|||||
/** |
|
||||
* buildStateOrigins |
|
||||
* |
|
||||
* Builds an object that details all the bound state in the application, and what updates it. |
|
||||
* |
|
||||
* @param screenDefinition - the screen definition metadata. |
|
||||
* @returns {Object} an object with the client state values and how they are managed. |
|
||||
*/ |
|
||||
export const buildStateOrigins = screenDefinition => { |
|
||||
const origins = {} |
|
||||
|
|
||||
function traverse(propValue) { |
|
||||
for (let key in propValue) { |
|
||||
if (!Array.isArray(propValue[key])) continue |
|
||||
|
|
||||
if (key === "_children") propValue[key].forEach(traverse) |
|
||||
|
|
||||
for (let element of propValue[key]) { |
|
||||
if (element["##eventHandlerType"] === "Set State") |
|
||||
origins[element.parameters.path] = element |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
traverse(screenDefinition.props) |
|
||||
|
|
||||
return origins |
|
||||
} |
|
||||
@ -1,32 +0,0 @@ |
|||||
import { buildStateOrigins } from "../src/builderStore/buildStateOrigins" |
|
||||
|
|
||||
it("builds the correct stateOrigins object from a screen definition with handlers", () => { |
|
||||
expect( |
|
||||
buildStateOrigins({ |
|
||||
name: "screen1", |
|
||||
description: "", |
|
||||
props: { |
|
||||
_component: "@budibase/standard-components/container", |
|
||||
className: "", |
|
||||
type: "div", |
|
||||
onClick: [ |
|
||||
{ |
|
||||
"##eventHandlerType": "Set State", |
|
||||
parameters: { |
|
||||
path: "testKey", |
|
||||
value: "value", |
|
||||
}, |
|
||||
}, |
|
||||
], |
|
||||
}, |
|
||||
}) |
|
||||
).toEqual({ |
|
||||
testKey: { |
|
||||
"##eventHandlerType": "Set State", |
|
||||
parameters: { |
|
||||
path: "testKey", |
|
||||
value: "value", |
|
||||
}, |
|
||||
}, |
|
||||
}) |
|
||||
}) |
|
||||
Loading…
Reference in new issue