Skip to content

Commit 5194e18

Browse files
committed
Move getLayout to dash_component_api
1 parent 664e6dd commit 5194e18

File tree

4 files changed

+37
-36
lines changed

4 files changed

+37
-36
lines changed

components/dash-core-components/src/components/Tabs.react.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export default class Tabs extends Component {
153153
}
154154
const children = this.parseChildrenToArray();
155155
if (children && children.length) {
156-
const firstChildren = window.dash_clientside.get_layout([
156+
const firstChildren = window.dash_component_api.getLayout([
157157
...children[0].props.componentPath,
158158
'props',
159159
'value',
@@ -193,7 +193,7 @@ export default class Tabs extends Component {
193193
let childProps;
194194

195195
if (React.isValidElement(child)) {
196-
childProps = window.dash_clientside.get_layout([
196+
childProps = window.dash_component_api.getLayout([
197197
...child.props.componentPath,
198198
'props',
199199
]);

dash/dash-renderer/src/dashApi.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
1+
import {path} from 'ramda';
12
import {DashContext, useDashContext} from './wrapper/DashContext';
3+
import {getPath} from './actions/paths';
4+
import {getStores} from './utils/stores';
5+
6+
/**
7+
* Get the dash props from a component path or id.
8+
*
9+
* @param componentPathOrId The path or the id of the component to get the props of.
10+
* @param propPath Additional key to get the property instead of plain props.
11+
* @returns
12+
*/
13+
function getLayout(componentPathOrId: string[] | string): any {
14+
const ds = getStores();
15+
for (let y = 0; y < ds.length; y++) {
16+
const {paths, layout} = ds[y].getState();
17+
let componentPath;
18+
if (!Array.isArray(componentPathOrId)) {
19+
componentPath = getPath(paths, componentPathOrId);
20+
} else {
21+
componentPath = componentPathOrId;
22+
}
23+
const props = path(componentPath, layout);
24+
if (props !== undefined) {
25+
return props;
26+
}
27+
}
28+
}
229

330
(window as any).dash_component_api = {
431
DashContext,
5-
useDashContext
32+
useDashContext,
33+
getLayout
634
};

dash/dash-renderer/src/utils/clientsideFunctions.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
import {path} from 'ramda';
2-
31
import {updateProps, notifyObservers} from '../actions/index';
42
import {getPath} from '../actions/paths';
5-
6-
function getStores() {
7-
const stores = ((window as any).dash_stores =
8-
(window as any).dash_stores || []);
9-
return stores;
10-
}
3+
import {getStores} from './stores';
114

125
/**
136
* Set the props of a dash component by id or path.
@@ -63,32 +56,7 @@ const clean_url = (url: string, fallback = 'about:blank') => {
6356
return url;
6457
};
6558

66-
/**
67-
* Get the dash props from a component path or id.
68-
*
69-
* @param componentPathOrId The path or the id of the component to get the props of.
70-
* @param propPath Additional key to get the property instead of plain props.
71-
* @returns
72-
*/
73-
function get_layout(componentPathOrId: string[] | string): any {
74-
const ds = getStores();
75-
for (let y = 0; y < ds.length; y++) {
76-
const {paths, layout} = ds[y].getState();
77-
let componentPath;
78-
if (!Array.isArray(componentPathOrId)) {
79-
componentPath = getPath(paths, componentPathOrId);
80-
} else {
81-
componentPath = componentPathOrId;
82-
}
83-
const props = path(componentPath, layout);
84-
if (props !== undefined) {
85-
return props;
86-
}
87-
}
88-
}
89-
9059
const dc = ((window as any).dash_clientside =
9160
(window as any).dash_clientside || {});
9261
dc['set_props'] = set_props;
9362
dc['clean_url'] = dc['clean_url'] === undefined ? clean_url : dc['clean_url'];
94-
dc['get_layout'] = get_layout;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function getStores() {
2+
const stores = ((window as any).dash_stores =
3+
(window as any).dash_stores || []);
4+
return stores;
5+
}

0 commit comments

Comments
 (0)