-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose setprops #2758
Merged
Merged
Expose setprops #2758
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
7eb975d
exposing `clientSide_setProps` by utilizing an observer
BSd3v 3c5bd45
Merge branch 'plotly:dev' into expose-setprops
BSd3v 8b17321
adding changelog and contributing entries
BSd3v 6b2f1de
adding changelog entry
BSd3v 647ee9f
updating naming convention to `setProps`
BSd3v 78ccd87
migrating `setProps` to be a util that gets imported and then created…
BSd3v 05446a9
adjusting `setProps` to use a `window.dash_stores` array which builds…
BSd3v be4ac5a
attempt to fail `install dependencies`
BSd3v 96c1115
adding ignore statements for the `window` object
BSd3v fc6c200
adjusting test for `dash_renderer.min.js` to be from script
BSd3v 3dbf133
failing on purpose
BSd3v 9f5ac40
adding ignore for `window` object again
BSd3v 1faf5e6
adjusting `setProps.ts` -> `clientsideFunctions.ts` and adding test f…
BSd3v ca5eaf8
fixing for lint
BSd3v 099e79a
fixing for lint
BSd3v 2a0c9ab
fixing missing import
BSd3v 7c11209
fixing for lint
BSd3v 26bb305
testing to make sure the store doesnt exist yet
BSd3v 107ea9f
fixing tyop and adjusting `setProps` -> `set_props`
BSd3v 1c8773a
Merge branch 'dev' into expose-setprops
T4rk1n daea03d
making `set_props` work with just a single component at a time
BSd3v f9734a5
removing eslint/ts-ignore comments
BSd3v 5bbfc4d
Merge branch 'dev' into expose-setprops
BSd3v 46c6d2b
fixing for lint
BSd3v File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
file=./build/dash_renderer.min.js | ||
if [ ! -f "$file" ]; then | ||
echo "dash-renderer did not build correctly" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import {DashRenderer} from './DashRenderer'; | ||
import './utils/clientsideFunctions'; | ||
|
||
// make DashRenderer globally available | ||
window.DashRenderer = DashRenderer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {updateProps, notifyObservers} from '../actions/index'; | ||
import {getPath} from '../actions/paths'; | ||
|
||
const set_props = (id: string | object, props: {[k: string]: any}) => { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
const ds = (window.dash_stores = window.dash_stores || []); | ||
for (let y = 0; y < ds.length; y++) { | ||
const {dispatch, getState} = ds[y]; | ||
const {paths} = getState(); | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
const componentPath = getPath(paths, id); | ||
dispatch( | ||
updateProps({ | ||
props, | ||
itempath: componentPath | ||
}) | ||
); | ||
dispatch(notifyObservers({id, props})); | ||
} | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
const dc = (window.dash_clientside = window.dash_clientside || {}); | ||
dc['set_props'] = set_props; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from dash import Dash, html, Input, Output, no_update, State | ||
import json | ||
from multiprocessing import Value | ||
|
||
|
||
def test_sp001_clientside_setprops(dash_duo): | ||
|
||
call_count = Value("i", 0) | ||
|
||
app = Dash(__name__) | ||
|
||
ids = [ | ||
{"id": {"index": "1", "type": "test"}, "children": ["rawr"]}, | ||
{"id": "two", "children": "this is a test"}, | ||
{"id": "three", "children": "i see trees of green"}, | ||
] | ||
|
||
app.layout = html.Div( | ||
[ | ||
*[html.Div(id=x["id"]) for x in ids], | ||
html.Div(id="four"), | ||
html.Button(id="setup", children="test setprops"), | ||
] | ||
) | ||
|
||
app.clientside_callback( | ||
""" | ||
() => { | ||
""" | ||
+ json.dumps(ids) | ||
+ """.forEach(({id, ...props}) => window.dash_clientside.set_props(id, props)) | ||
return window.dash_clientside.no_update | ||
} | ||
""", | ||
Output("setup", "id"), | ||
Input("setup", "n_clicks"), | ||
prevent_initial_call=True, | ||
) | ||
|
||
for x in ids: | ||
|
||
@app.callback( | ||
Output(x["id"], "id", allow_duplicate=True), | ||
Output("four", "children", allow_duplicate=True), | ||
Input(x["id"], "children"), | ||
State(x["id"], "id"), | ||
prevent_initial_call=True, | ||
) | ||
def prinout(c, id): | ||
call_count.value += 1 | ||
for y in ids: | ||
if y["id"] == id: | ||
assert y["children"] == c | ||
return no_update, call_count.value | ||
|
||
dash_duo.start_server(app) | ||
|
||
dash_duo.wait_for_text_to_equal("#setup", "test setprops") | ||
dash_duo.find_element("#setup").click() | ||
dash_duo.wait_for_text_to_equal("#two", "this is a test") | ||
dash_duo.wait_for_text_to_equal("#three", "i see trees of green") | ||
dash_duo.wait_for_text_to_equal("#four", "3") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My TypeScript skills are pretty basic, but can't we avoid these comments (3 in this file and
store.ts
) with a few well-placedas any
or some such? @T4rk1n you're better at this than I am, can you comment?