Skip to content
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 24 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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 Feb 13, 2024
3c5bd45
Merge branch 'plotly:dev' into expose-setprops
BSd3v Feb 14, 2024
8b17321
adding changelog and contributing entries
BSd3v Feb 14, 2024
6b2f1de
adding changelog entry
BSd3v Feb 14, 2024
647ee9f
updating naming convention to `setProps`
BSd3v Feb 14, 2024
78ccd87
migrating `setProps` to be a util that gets imported and then created…
BSd3v Feb 14, 2024
05446a9
adjusting `setProps` to use a `window.dash_stores` array which builds…
BSd3v Feb 14, 2024
be4ac5a
attempt to fail `install dependencies`
BSd3v Feb 14, 2024
96c1115
adding ignore statements for the `window` object
BSd3v Feb 14, 2024
fc6c200
adjusting test for `dash_renderer.min.js` to be from script
BSd3v Feb 14, 2024
3dbf133
failing on purpose
BSd3v Feb 14, 2024
9f5ac40
adding ignore for `window` object again
BSd3v Feb 14, 2024
1faf5e6
adjusting `setProps.ts` -> `clientsideFunctions.ts` and adding test f…
BSd3v Feb 15, 2024
ca5eaf8
fixing for lint
BSd3v Feb 15, 2024
099e79a
fixing for lint
BSd3v Feb 15, 2024
2a0c9ab
fixing missing import
BSd3v Feb 15, 2024
7c11209
fixing for lint
BSd3v Feb 15, 2024
26bb305
testing to make sure the store doesnt exist yet
BSd3v Feb 15, 2024
107ea9f
fixing tyop and adjusting `setProps` -> `set_props`
BSd3v Feb 15, 2024
1c8773a
Merge branch 'dev' into expose-setprops
T4rk1n Feb 16, 2024
daea03d
making `set_props` work with just a single component at a time
BSd3v Feb 21, 2024
f9734a5
removing eslint/ts-ignore comments
BSd3v Feb 27, 2024
5bbfc4d
Merge branch 'dev' into expose-setprops
BSd3v Feb 27, 2024
46c6d2b
fixing for lint
BSd3v Feb 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ This project adheres to [Semantic Versioning](https://semver.org/).
## Fixed

- [#2756](https://github.com/plotly/dash/pull/2756) Prevent false dangerous link warning. Fixes [#2743](https://github.com/plotly/dash/issues/2743)
- [#2752](https://github.com/plotly/dash/pull/2752) Fixed issue with Windows build, for first time build on Windows, the dev needs to use `npm run first-build`

## Changed

- [#2734](https://github.com/plotly/dash/pull/2734) Configure CI for Python 3.10 [#1863](https://github.com/plotly/dash/issues/1863)
- [#2735](https://github.com/plotly/dash/pull/2735) Configure CI for Python 3.8 and 3.12, drop support for Python 3.6 and Python 3.7 [#2736](https://github.com/plotly/dash/issues/2736)

## Added

- [#2758](https://github.com/plotly/dash/pull/2758)
- exposing `setProps` to `dash_clientside.clientSide_setProps` to allow for JS code to interact directly with the dash eco-system

## [2.15.0] - 2024-01-31

## Added
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ $ npm ci
#
$ npm run build # runs `renderer build` and `npm build` in dcc, html, table
# build and install components used in tests
# on windows, the developer will need to use `npm run first-build` this performs additional first steps
#
# Alternatively one could run part of the build process e.g.
$ dash-update-components "dash-core-components"
Expand Down
30 changes: 30 additions & 0 deletions dash/dash-renderer/src/observers/setProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

import {IStoreState} from '../store';
import {updateProps, notifyObservers} from '../actions/index'

const observer: IStoreObserverDefinition<IStoreState> = {
observer: ({dispatch, getState}) => {
const setProps = (updates: {}) => {
const {paths} = getState()
Object.entries(updates).forEach(([componentId, props]) => {
const componentPath = paths.strs[componentId];
dispatch(
updateProps({
props,
itempath: componentPath
})
);
dispatch(
notifyObservers({id: componentId, props})
);
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "observer" pattern in this redux context is very weird, it's meant to act as reducer with side effects.
I think this will be called on every callbacks and it should be only defined once. Maybe just move the definition on the window to store.ts in createApp instead would be better.

Copy link
Contributor Author

@BSd3v BSd3v Feb 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Within this context (line 58 store.ts):

private createAppStore = (reducer: any, middleware: any) => {
        this.__store = createStore(reducer, middleware);
        this.storeObserver.setStore(this.__store);
        this.setObservers();
    };



window.dash_clientside = window.dash_clientside || {};
window.dash_clientside['setProps'] = setProps
},
inputs: ['callbacks.executed']
};

export default observer;
2 changes: 2 additions & 0 deletions dash/dash-renderer/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import loadingMap from './observers/loadingMap';
import prioritizedCallbacks from './observers/prioritizedCallbacks';
import requestedCallbacks from './observers/requestedCallbacks';
import storedCallbacks from './observers/storedCallbacks';
import setProps from './observers/setProps';

export interface IStoreState {
callbacks: ICallbacksState;
Expand Down Expand Up @@ -51,6 +52,7 @@ export default class RendererStore {
observe(executingCallbacks);
observe(executedCallbacks);
observe(storedCallbacks);
observe(setProps);
});

private createAppStore = (reducer: any, middleware: any) => {
Expand Down