|
@@ -1,7 +1,7 @@
|
|
// Copyright (c) Jupyter Development Team.
|
|
// Copyright (c) Jupyter Development Team.
|
|
// Distributed under the terms of the Modified BSD License.
|
|
// Distributed under the terms of the Modified BSD License.
|
|
|
|
|
|
-import React, { useState } from 'react';
|
|
|
|
|
|
+import React, { useEffect, useState } from 'react';
|
|
import { Breakpoints } from '.';
|
|
import { Breakpoints } from '.';
|
|
import { ReactWidget } from '@jupyterlab/apputils';
|
|
import { ReactWidget } from '@jupyterlab/apputils';
|
|
import { ArrayExt } from '@phosphor/algorithm';
|
|
import { ArrayExt } from '@phosphor/algorithm';
|
|
@@ -24,14 +24,23 @@ export class Body extends ReactWidget {
|
|
const BreakpointsComponent = ({ model }: { model: Breakpoints.Model }) => {
|
|
const BreakpointsComponent = ({ model }: { model: Breakpoints.Model }) => {
|
|
const [breakpoints, setBreakpoints] = useState(model.breakpoints);
|
|
const [breakpoints, setBreakpoints] = useState(model.breakpoints);
|
|
|
|
|
|
- model.breakpointsChanged.connect(
|
|
|
|
- (_: Breakpoints.Model, updates: Breakpoints.IBreakpoint[]) => {
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ const updateBreakpoints = (
|
|
|
|
+ _: Breakpoints.Model,
|
|
|
|
+ updates: Breakpoints.IBreakpoint[]
|
|
|
|
+ ) => {
|
|
if (ArrayExt.shallowEqual(breakpoints, updates)) {
|
|
if (ArrayExt.shallowEqual(breakpoints, updates)) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
setBreakpoints(updates);
|
|
setBreakpoints(updates);
|
|
- }
|
|
|
|
- );
|
|
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ model.breakpointsChanged.connect(updateBreakpoints);
|
|
|
|
+
|
|
|
|
+ return () => {
|
|
|
|
+ model.breakpointsChanged.disconnect(updateBreakpoints);
|
|
|
|
+ };
|
|
|
|
+ });
|
|
|
|
|
|
return (
|
|
return (
|
|
<div>
|
|
<div>
|
|
@@ -56,16 +65,25 @@ const BreakpointComponent = ({
|
|
const [active, setActive] = useState(breakpoint.active);
|
|
const [active, setActive] = useState(breakpoint.active);
|
|
breakpoint.active = active;
|
|
breakpoint.active = active;
|
|
|
|
|
|
- breakpointChanged.connect(
|
|
|
|
- (_: Breakpoints.Model, updates: Breakpoints.IBreakpoint) => {
|
|
|
|
- setActive(updates.active);
|
|
|
|
- }
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
const setBreakpointEnabled = (state: boolean) => {
|
|
const setBreakpointEnabled = (state: boolean) => {
|
|
setActive(state);
|
|
setActive(state);
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ const updateBreakpoints = (
|
|
|
|
+ _: Breakpoints.Model,
|
|
|
|
+ updates: Breakpoints.IBreakpoint
|
|
|
|
+ ) => {
|
|
|
|
+ setBreakpointEnabled(updates.active);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ breakpointChanged.connect(updateBreakpoints);
|
|
|
|
+
|
|
|
|
+ return () => {
|
|
|
|
+ breakpointChanged.disconnect(updateBreakpoints);
|
|
|
|
+ };
|
|
|
|
+ });
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<div className={`breakpoint`}>
|
|
<div className={`breakpoint`}>
|
|
<input
|
|
<input
|