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

Upgrade immer to 10.1.1 #2993

Merged
merged 2 commits into from
Aug 14, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions frontend/common/Binder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import immer from "../imports/immer.js"
import { produce } from "../imports/immer.js"
import { timeout_promise, ws_address_from_base } from "./PlutoConnection.js"
import { with_query_params } from "./URLTools.js"

Expand Down Expand Up @@ -95,7 +95,7 @@ export const start_binder = async ({ setStatePromise, connect, launch_params })
// view stats on https://stats.plutojl.org/
count_stat(`binder-start`)
await setStatePromise(
immer((/** @type {import("../components/Editor.js").EditorState} */ state) => {
produce((/** @type {import("../components/Editor.js").EditorState} */ state) => {
state.backend_launch_phase = BackendLaunchPhase.requesting
state.disable_ui = false
// Clear the Status of the process that generated the HTML
Expand All @@ -107,7 +107,7 @@ export const start_binder = async ({ setStatePromise, connect, launch_params })
const { binder_session_url, binder_session_token } = await request_binder(launch_params.binder_url.replace("mybinder.org/v2/", "mybinder.org/build/"), {
on_log: (logs) =>
setStatePromise(
immer((/** @type {import("../components/Editor.js").EditorState} */ state) => {
produce((/** @type {import("../components/Editor.js").EditorState} */ state) => {
state.backend_launch_logs = logs
})
),
Expand All @@ -122,7 +122,7 @@ export const start_binder = async ({ setStatePromise, connect, launch_params })
}

await setStatePromise(
immer((/** @type {import("../components/Editor.js").EditorState} */ state) => {
produce((/** @type {import("../components/Editor.js").EditorState} */ state) => {
state.backend_launch_phase = BackendLaunchPhase.created
state.binder_session_url = binder_session_url
state.binder_session_token = binder_session_token
Expand All @@ -133,7 +133,7 @@ export const start_binder = async ({ setStatePromise, connect, launch_params })
await fetch(with_token(binder_session_url))

await setStatePromise(
immer((/** @type {import("../components/Editor.js").EditorState} */ state) => {
produce((/** @type {import("../components/Editor.js").EditorState} */ state) => {
state.backend_launch_phase = BackendLaunchPhase.responded
})
)
Expand Down Expand Up @@ -197,7 +197,7 @@ export const start_binder = async ({ setStatePromise, connect, launch_params })
console.info("notebook_id:", new_notebook_id)

await setStatePromise(
immer((/** @type {import("../components/Editor.js").EditorState} */ state) => {
produce((/** @type {import("../components/Editor.js").EditorState} */ state) => {
state.notebook.notebook_id = new_notebook_id
state.backend_launch_phase = BackendLaunchPhase.notebook_running
state.refresh_target = edit_url
Expand Down
6 changes: 3 additions & 3 deletions frontend/common/RunLocal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import immer from "../imports/immer.js"
import { produce } from "../imports/immer.js"
import { BackendLaunchPhase } from "./Binder.js"
import { timeout_promise } from "./PlutoConnection.js"
import { with_query_params } from "./URLTools.js"
Expand All @@ -18,7 +18,7 @@ export const start_local = async ({ setStatePromise, connect, launch_params }) =
if (launch_params.pluto_server_url == null || launch_params.notebookfile == null) throw Error("Invalid launch parameters for starting locally.")

await setStatePromise(
immer((/** @type {import("../components/Editor.js").EditorState} */ state) => {
produce((/** @type {import("../components/Editor.js").EditorState} */ state) => {
state.backend_launch_phase = BackendLaunchPhase.responded
state.disable_ui = false
// Clear the Status of the process that generated the HTML
Expand Down Expand Up @@ -63,7 +63,7 @@ export const start_local = async ({ setStatePromise, connect, launch_params }) =
window.history.replaceState({}, "", edit_url)

await setStatePromise(
immer((/** @type {import("../components/Editor.js").EditorState} */ state) => {
produce((/** @type {import("../components/Editor.js").EditorState} */ state) => {
state.notebook.notebook_id = new_notebook_id
state.backend_launch_phase = BackendLaunchPhase.notebook_running
})
Expand Down
24 changes: 17 additions & 7 deletions frontend/common/SliderServerClient.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { trailingslash } from "./Binder.js"
import { plutohash_arraybuffer, debounced_promises, base64url_arraybuffer } from "./PlutoHash.js"
import { pack, unpack } from "./MsgPack.js"
import immer from "../imports/immer.js"
import { produce } from "../imports/immer.js"
import _ from "../imports/lodash.js"

const assert_response_ok = (/** @type {Response} */ r) => (r.ok ? r : Promise.reject(r))
Expand Down Expand Up @@ -39,9 +39,19 @@ export const nothing_actions = ({ actions }) =>
])
)

/**
* @param {{
* setStatePromise: any,
* launch_params: import("../components/Editor.js").LaunchParameters,
* actions: any,
* get_original_state: () => import("../components/Editor.js").NotebookData,
* get_current_state: () => import("../components/Editor.js").NotebookData,
* apply_notebook_patches: (patches: import("../imports/immer.js").Patch[], old_state?: import("../components/Editor.js").NotebookData?, get_reverse_patches?: boolean) => Promise<any>,
* }} props
*/
export const slider_server_actions = ({ setStatePromise, launch_params, actions, get_original_state, get_current_state, apply_notebook_patches }) => {
setStatePromise(
immer((state) => {
produce((/** @type {import("../components/Editor.js").EditorState} */ state) => {
state.slider_server.connecting = true
})
)
Expand All @@ -62,7 +72,7 @@ export const slider_server_actions = ({ setStatePromise, launch_params, actions,
bond_connections.then((x) => {
console.log("Bond connections:", x)
setStatePromise(
immer((state) => {
produce((/** @type {import("../components/Editor.js").EditorState} */ state) => {
state.slider_server.connecting = false
state.slider_server.interactive = Object.keys(x).length > 0
})
Expand All @@ -85,7 +95,7 @@ export const slider_server_actions = ({ setStatePromise, launch_params, actions,

const update_cells_running = async (running) =>
await setStatePromise(
immer((state) => {
produce((/** @type {import("../components/Editor.js").EditorState} */ state) => {
running_cells.forEach((cell_id) => (state.notebook.cell_results[cell_id][starts.has(cell_id) ? "running" : "queued"] = running))
})
)
Expand Down Expand Up @@ -128,12 +138,12 @@ export const slider_server_actions = ({ setStatePromise, launch_params, actions,

await apply_notebook_patches(
patches,
immer((state) => {
produce(get_current_state(), (state) => {
const original = get_original_state()
ids_of_cells_that_ran.forEach((id) => {
state.cell_results[id] = original.cell_results[id]
})
})(get_current_state())
})
)
} catch (e) {
console.error(unpacked, e)
Expand All @@ -148,7 +158,7 @@ export const slider_server_actions = ({ setStatePromise, launch_params, actions,
...nothing_actions({ actions }),
set_bond: async (symbol, value) => {
setStatePromise(
immer((state) => {
produce((/** @type {import("../components/Editor.js").EditorState} */ state) => {
state.notebook.bonds[symbol] = { value: value }
})
)
Expand Down
24 changes: 14 additions & 10 deletions frontend/components/Editor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { html, Component } from "../imports/Preact.js"
import * as preact from "../imports/Preact.js"
import immer, { applyPatches, produceWithPatches } from "../imports/immer.js"
import { produce, applyPatches, produceWithPatches } from "../imports/immer.js"
import _ from "../imports/lodash.js"

import { empty_notebook_state, set_disable_ui_css } from "../editor.js"
Expand All @@ -20,7 +20,7 @@ import { Scroller } from "./Scroller.js"
import { ExportBanner } from "./ExportBanner.js"
import { Popup } from "./Popup.js"

import { slice_utf8, length_utf8 } from "../common/UnicodeTools.js"
import { slice_utf8 } from "../common/UnicodeTools.js"
import {
has_ctrl_or_cmd_pressed,
ctrl_or_cmd_name,
Expand Down Expand Up @@ -297,6 +297,10 @@ export const url_logo_small = document.head.querySelector("link[rel='pluto-logo-
* extended_components: any,
* is_recording: boolean,
* recording_waiting_to_start: boolean,
* slider_server: {
* connecting: boolean,
* interactive: boolean,
* },
* }}
*/

Expand Down Expand Up @@ -365,7 +369,7 @@ export class Editor extends Component {
set_doc_query: (query) => this.setState({ desired_doc_query: query }),
set_local_cell: (cell_id, new_val) => {
return this.setStatePromise(
immer((/** @type {EditorState} */ state) => {
produce((/** @type {EditorState} */ state) => {
state.cell_inputs_local[cell_id] = {
code: new_val,
}
Expand Down Expand Up @@ -422,7 +426,7 @@ export class Editor extends Component {
* See ** 1 **
*/
this.setState(
immer((/** @type {EditorState} */ state) => {
produce((/** @type {EditorState} */ state) => {
// Deselect everything first, to clean things up
state.selected_cells = []

Expand Down Expand Up @@ -460,7 +464,7 @@ export class Editor extends Component {
const new_code = `${block_start}\n\t${cell.code.replace(/\n/g, "\n\t")}\n${block_end}`

await this.setStatePromise(
immer((/** @type {EditorState} */ state) => {
produce((/** @type {EditorState} */ state) => {
state.cell_inputs_local[cell_id] = {
code: new_code,
}
Expand Down Expand Up @@ -488,7 +492,7 @@ export class Editor extends Component {
})

this.setState(
immer((/** @type {EditorState} */ state) => {
produce((/** @type {EditorState} */ state) => {
for (let cell of cells_to_add) {
state.cell_inputs_local[cell.cell_id] = cell
}
Expand Down Expand Up @@ -617,7 +621,7 @@ export class Editor extends Component {
// This is a "dirty" trick, as this should actually be stored in some shared request_status => status state
// But for now... this is fine 😼
await this.setStatePromise(
immer((/** @type {EditorState} */ state) => {
produce((/** @type {EditorState} */ state) => {
for (let cell_id of cell_ids) {
if (state.notebook.cell_results[cell_id] != null) {
state.notebook.cell_results[cell_id].queued = this.is_process_ready()
Expand Down Expand Up @@ -691,7 +695,7 @@ export class Editor extends Component {
let _copy_of_patches,
reverse_of_patches = []
this.setState(
immer((/** @type {EditorState} */ state) => {
produce((/** @type {EditorState} */ state) => {
let new_notebook
try {
// To test this, uncomment the lines below:
Expand Down Expand Up @@ -1170,7 +1174,7 @@ patch: ${JSON.stringify(
window.plutoDesktop?.ipcRenderer.once("PLUTO-MOVE-NOTEBOOK", async (/** @type {string?} */ loc) => {
if (!!loc)
await this.setStatePromise(
immer((/** @type {EditorState} */ state) => {
produce((/** @type {EditorState} */ state) => {
state.notebook.in_temp_dir = false
state.notebook.path = loc
})
Expand Down Expand Up @@ -1640,7 +1644,7 @@ The notebook file saves every time you run a cell.`
apply_notebook_patches=${this.apply_notebook_patches}
reset_notebook_state=${() =>
this.setStatePromise(
immer((/** @type {EditorState} */ state) => {
produce((/** @type {EditorState} */ state) => {
state.notebook = this.props.initial_notebook_state
})
)}
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/Editor/LaunchBackendButton.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { html, useMemo, useEffect } from "../../imports/Preact.js"
import { html, useMemo } from "../../imports/Preact.js"
import * as preact from "../../imports/Preact.js"
import { RunLocalButton, BinderButton } from "../EditOrRunButton.js"
import { start_local } from "../../common/RunLocal.js"
import { BackendLaunchPhase, start_binder } from "../../common/Binder.js"
import immer, { applyPatches, produceWithPatches } from "../../imports/immer.js"
import { produce } from "../../imports/immer.js"

export const EditorLaunchBackendButton = ({ editor, launch_params, status }) => {
try {
const EnvRun = useMemo(
// @ts-ignore
() => window?.pluto_injected_environment?.environment?.({ client: editor.client, editor, imports: { immer, preact } })?.custom_run_or_edit,
() => window?.pluto_injected_environment?.environment?.({ client: editor.client, editor, imports: { immer: produce, preact } })?.custom_run_or_edit,
[editor.client, editor]
)
// @ts-ignore
Expand Down
8 changes: 4 additions & 4 deletions frontend/components/FrontmatterInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import _ from "../imports/lodash.js"
import "https://cdn.jsdelivr.net/gh/fonsp/rebel-tag-input@1.0.6/lib/rebel-tag-input.mjs"

//@ts-ignore
import immer from "../imports/immer.js"
import { produce } from "../imports/immer.js"
import { useDialog } from "../common/useDialog.js"
import { FeaturedCard } from "./welcome/FeaturedCard.js"
import { useEventListener } from "../common/useEventListener.js"
Expand All @@ -26,7 +26,7 @@ export const FrontMatterInput = ({ filename, remote_frontmatter, set_remote_fron

const fm_setter = (key) => (value) =>
set_frontmatter(
immer((fm) => {
produce((fm) => {
_.set(fm, key, value)
})
)
Expand Down Expand Up @@ -83,7 +83,7 @@ export const FrontMatterInput = ({ filename, remote_frontmatter, set_remote_fron
onClick=${() => {
// TODO
set_frontmatter(
immer((fm) => {
produce((fm) => {
_.unset(fm, path)
})
)
Expand All @@ -99,7 +99,7 @@ export const FrontMatterInput = ({ filename, remote_frontmatter, set_remote_fron
const fieldname = prompt("Field name:")
if (fieldname) {
set_frontmatter(
immer((fm) => {
produce((fm) => {
_.set(fm, `${base_path}${fieldname}`, null)
})
)
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/LiveDocsTab.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { html, useState, useRef, useLayoutEffect, useEffect, useMemo, useContext } from "../imports/Preact.js"
import immer from "../imports/immer.js"
import { produce } from "../imports/immer.js"
import observablehq from "../common/SetupCellEnvironment.js"

import { RawHTMLContainer, highlight } from "./CellOutput.js"
Expand All @@ -26,7 +26,7 @@ export let LiveDocsTab = ({ focus_on_open, desired_doc_query, on_update_doc_quer
body: `<p>Welcome to the <b>Live docs</b>! Keep this little window open while you work on the notebook, and you will get documentation of everything you type!</p><p>You can also type a query above.</p><hr><p><em>Still stuck? Here are <a target="_blank" href="https://julialang.org/about/help/">some tips</a>.</em></p>`,
loading: false,
})
let update_state = (mutation) => set_state(immer((state) => mutation(state)))
let update_state = (mutation) => set_state(produce((state) => mutation(state)))

useEffect(() => {
if (state.loading) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/RecordingUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _ from "../imports/lodash.js"
import { createSilentAudio, create_recorder } from "../common/AudioRecording.js"
import { html, useEffect, useState, useRef, useCallback, useLayoutEffect, useMemo } from "../imports/Preact.js"
import { AudioPlayer } from "./AudioPlayer.js"
import immer from "../imports/immer.js"
import { produce } from "../imports/immer.js"
import { base64_arraybuffer, blob_url_to_data_url } from "../common/PlutoHash.js"
import { pack, unpack } from "../common/MsgPack.js"

Expand Down
Loading
Loading