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

Add UseSignal example to the docs #7519

Merged
merged 1 commit into from Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions docs/source/developer/virtualdom.rst
Expand Up @@ -34,8 +34,13 @@ override the ``render`` method to return a React element:

We use Phosphor `Signals <https://phosphorjs.github.io/phosphor/api/signaling/interfaces/isignal.html>`__ to represent
data that changes over time in JupyterLab.
To have your React element change in response to a signal event, use the ``UseSignal`` component,
which implements the `"render props" <https://reactjs.org/docs/render-props.html>`__.
To have your React element change in response to a signal event, use the ``UseSignal`` component from ``@jupyterlab/apputils``,
which implements the `"render props" <https://reactjs.org/docs/render-props.html>`__:


.. literalinclude:: virtualdom.usesignal.tsx
:force:


The `running component <https://github.com/jupyterlab/jupyterlab/blob/f2e0cde0e7c960dc82fd9b010fcd3dbd9e9b43d0/packages/running/src/index.tsx#L157-L159>`__
and the ``createSearchOverlay`` function in the `search overlay <https://github.com/jupyterlab/jupyterlab/blob/f2e0cde0e7c960dc82fd9b010fcd3dbd9e9b43d0/packages/documentsearch/src/searchoverlay.tsx#L440-L457>`__
Expand Down
25 changes: 25 additions & 0 deletions docs/source/developer/virtualdom.usesignal.tsx
@@ -0,0 +1,25 @@
import * as React from 'react';

import { ReactWidget, UseSignal } from '@jupyterlab/apputils';

import { ISignal, Signal } from '@phosphor/signaling';

import { Widget } from '@phosphor/widgets';

function MyComponent() {
return <div>My Widget</div>;
}

function UseSignalComponent(props: { signal: ISignal<MyWidget, void> }) {
return <UseSignal signal={props.signal}>{() => <MyComponent />}</UseSignal>;
}

class MyWidget extends ReactWidget {
render() {
return <UseSignalComponent signal={this._signal} />;
}

private _signal = new Signal<this, void>(this);
}

const myWidget: Widget = new MyWidget();