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

Dralbase state managment #710

Merged
merged 70 commits into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
d8beabe
"What if I start small"
dralletje Nov 24, 2020
a5bae21
Hey there
dralletje Nov 25, 2020
90d022f
Take this
dralletje Nov 25, 2020
4bea727
Okay this then
dralletje Nov 25, 2020
1cf3bed
Bonds now triggering less often
dralletje Nov 25, 2020
a52e779
Cool cool
dralletje Nov 26, 2020
e8811c9
Remove cells!!!
dralletje Nov 26, 2020
8204a0f
Cell focus and some stuff
dralletje Nov 26, 2020
b31e795
Memo
dralletje Nov 26, 2020
b49579d
Merge branch 'master' into firebase-like-state-managment
dralletje Nov 27, 2020
a30969f
So much
dralletje Nov 27, 2020
e4262d0
Not yet
dralletje Nov 27, 2020
8f7daca
Merge branch 'master' into firebase-like-state-managment
dralletje Nov 27, 2020
bc66757
Merge branch 'master' into firebase-like-state-managment
dralletje Nov 27, 2020
96798e4
Honestly the tests didn't make much sense anyway
dralletje Nov 28, 2020
9f8ec08
Merge branch 'master' into firebase-like-state-managment
dralletje Nov 28, 2020
0ca86c5
asd
dralletje Nov 28, 2020
009e55a
Merge branch 'master' into firebase-like-state-managment
dralletje Nov 28, 2020
d3e2e48
Oof
dralletje Nov 28, 2020
bd163c5
Merge branch 'master' into firebase-like-state-managment
dralletje Nov 30, 2020
bea50e8
Error needs some work but sure
dralletje Nov 30, 2020
8853ed6
Make bonds always change
dralletje Nov 30, 2020
53a6cd9
Bonds are now shared
dralletje Nov 30, 2020
8593789
Splitting cells
dralletje Dec 1, 2020
56ecce7
Merge branch 'master' into firebase-like-state-managment
dralletje Dec 1, 2020
c1706c9
123
dralletje Dec 2, 2020
90ab8b4
Merge branch 'master' into firebase-like-state-managment
dralletje Dec 2, 2020
0a5368e
Submit all changes!
dralletje Dec 2, 2020
83def25
Merge branch 'master' into firebase-like-state-managment
fonsp Dec 10, 2020
c02cde1
Fix multiple def error
fonsp Dec 10, 2020
c422148
dralbase nb - tiny cleanup - sorry for big diff
fonsp Dec 10, 2020
cf69031
Merge branch 'master' into firebase-like-state-managment
fonsp Dec 11, 2020
05a0a60
moved cells -- nothing else this time
fonsp Dec 11, 2020
71f78c9
Merge branch 'master' into firebase-like-state-managment
fonsp Dec 11, 2020
7e2059d
make functions named so that stack traces are easier
fonsp Dec 11, 2020
3770c83
run cells after undoing delete like before
fonsp Dec 11, 2020
893de5d
tweak undodelete timer
fonsp Dec 11, 2020
d4032c2
move exportbanner to its own file
fonsp Dec 11, 2020
5efd9a6
Merge branch 'master' into firebase-like-state-managment
fonsp Dec 11, 2020
a901a7a
merge master
fonsp Dec 11, 2020
4f34cb8
sync code changes among clients
fonsp Dec 11, 2020
8855bc1
Fix Ctrl+Enter
fonsp Dec 11, 2020
e35e470
Merge branch 'master' into firebase-like-state-managment
fonsp Dec 11, 2020
c9e1e32
notebook loading performance
fonsp Dec 11, 2020
14d340f
Save file on reorder and fold & prevent double/triple file saves
fonsp Dec 11, 2020
30f2c78
Merge branch 'master' into firebase-like-state-managment
fonsp Dec 12, 2020
24b9185
homemade uuid
fonsp Dec 12, 2020
db81dcf
Fix splitting cells error click thing
fonsp Dec 12, 2020
7328969
Merge branch 'master' into firebase-like-state-managment
dralletje Dec 15, 2020
048af75
rename to Firebasey
fonsp Dec 19, 2020
a0e8697
Rename to cell_inputs, cell_results
fonsp Dec 19, 2020
079ef2f
Fix pasting and dropping cells
fonsp Dec 19, 2020
6d3beff
Fix show-more-items
fonsp Dec 19, 2020
59763e2
iterate dict directly
fonsp Dec 20, 2020
5b809fa
Merge branch 'master' into firebase-like-state-managment
dralletje Dec 20, 2020
38f3c00
deze moest nog
fonsp Dec 20, 2020
9a75749
upgrade immer to fix png display
fonsp Dec 20, 2020
cc4a2bb
fix array of tables
fonsp Dec 20, 2020
1c169de
Remove logging code from Dynamic.jl
fonsp Dec 20, 2020
61bdb40
Reset bonds when redefined
fonsp Dec 21, 2020
2f2e049
rename NotebookRequest to ClientRequest and use it for everything
fonsp Dec 21, 2020
51aa25c
moved code around
fonsp Dec 21, 2020
5a8a629
Remove old name from recent notebooks after rename
fonsp Dec 21, 2020
3b54a1a
forgot to rename
fonsp Dec 21, 2020
403e7f3
Merge branch 'master' into firebase-like-state-managment
dralletje Dec 24, 2020
5181586
Merge branch 'firebase-like-state-managment' of https://github.com/fo…
dralletje Dec 24, 2020
f93c043
Dralbase state managment: Fix front-end tests (#809)
Dec 29, 2020
2e291e9
Merge branch 'master' into firebase-like-state-managment
fonsp Dec 29, 2020
3d69884
Merge branch 'firebase-like-state-managment' of https://github.com/fo…
fonsp Dec 29, 2020
cd7178f
Update PlutoConnection.js
fonsp Dec 29, 2020
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
33 changes: 23 additions & 10 deletions frontend/common/Bond.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,44 @@

import observablehq from "./SetupCellEnvironment.js"

export const connect_bonds = (node, all_completed_promise, cell_invalidated_promise, requests) => {
export const set_bound_elements_to_their_value = (node, bond_values) => {
for (let bond_node of node.querySelectorAll("bond")) {
let bond_name = bond_node.getAttribute("def")
if (bond_node.firstElementChild != null && bond_values[bond_name] != null) {
bond_node.firstElementChild.value = bond_values[bond_name].value
}
}
}

/**
* @param {HTMLElement} node
* @param {(name: string, value_to_send: any, is_first_value: boolean) => void} on_bond_change
*/
export const add_bonds_listener = (node, on_bond_change) => {
// the <bond> node will be invalidated when the cell re-evaluates. when this happens, we need to stop processing input events
var node_is_invalidated = false

node.querySelectorAll("bond").forEach(async (bond_node) => {
// read the docs on Generators.input from observablehq/stdlib:
const inputs = observablehq.Generators.input(bond_node.firstElementChild)
var is_first_value = true

// the <bond> node will be invalidated when the cell re-evaluates. when this happens, we need to stop processing input events
var node_is_invalidated = false
cell_invalidated_promise.then(() => {
node_is_invalidated = true
})

while (!node_is_invalidated) {
// wait for all (other) cells to complete - if we don't, the Julia code would get overloaded with new values
await all_completed_promise.current
// wait for a new input value. If a value is ready, then this promise resolves immediately
const val = await inputs.next().value
if (!node_is_invalidated) {
// send to the Pluto back-end (have a look at set_bond in Editor.js)
const to_send = await transformed_val(val)
requests.set_bond(bond_node.getAttribute("def"), to_send, is_first_value)
on_bond_change(bond_node.getAttribute("def"), to_send, is_first_value)
}
// the first value might want to be ignored - https://github.com/fonsp/Pluto.jl/issues/275
is_first_value = false
}
})

return function dispose_bond_listener() {
node_is_invalidated = true
}
}

// The identity function in most cases, loads file contents when appropriate
Expand All @@ -38,6 +50,7 @@ const transformed_val = async (val) => {
} else if (val instanceof File) {
return await new Promise((res) => {
const reader = new FileReader()
// @ts-ignore
reader.onload = () => res({ name: val.name, type: val.type, data: new Uint8Array(reader.result) })
reader.onerror = () => res({ name: val.name, type: val.type, data: null })
reader.readAsArrayBuffer(val)
Expand Down
42 changes: 31 additions & 11 deletions frontend/common/Feedback.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { code_differs } from "../components/Cell.js"
import { timeout_promise } from "./PlutoConnection.js"

export const create_counter_statistics = () => {
Expand All @@ -9,7 +8,7 @@ export const create_counter_statistics = () => {
}
}

const first_line = (cell) => /(.*)/.exec(cell.local_code.body)[0]
const first_line = (cell) => /(.*)/.exec(cell.code)[0]
const count_matches = (pattern, haystack) => (haystack.match(pattern) || []).length
const value_counts = (values) =>
values.reduce((prev_counts, val) => {
Expand All @@ -18,30 +17,45 @@ const value_counts = (values) =>
}, {})
const sum = (values) => values.reduce((a, b) => a + b, 0)

/**
* @param {{
* notebook: import("../components/Editor.js").NotebookData
* cell_inputs_local: { [id: string]: import("../components/Editor.js").CellInputData }
* }} state
* */
export const finalize_statistics = async (state, client, counter_statistics) => {
const cells = state.notebook.cells
const cell_results = state.notebook.cell_order.map((cell_id) => state.notebook.cell_results[cell_id]).filter((x) => x != null)
const cells = state.notebook.cell_order.map((cell_id) => state.notebook.cell_inputs[cell_id]).filter((x) => x != null)
const cell_inputs_local = state.notebook.cell_order.map((cell_id) => {
return {
...(state.cell_inputs_local[cell_id] ?? state.notebook.cell_inputs[cell_id]),
...state.cell_inputs_local[cell_id],
}
})

const statistics = {
numCells: cells.length,
// integer
numErrored: cells.filter((c) => c.errored).length,
numErrored: cell_results.filter((c) => c.errored).length,
// integer
numFolded: cells.filter((c) => c.code_folded).length,
// integer
numCodeDiffers: cells.filter(code_differs).length,
numCodeDiffers: state.notebook.cell_order.filter(
(cell_id) => state.notebook.cell_inputs[cell_id].code === (state.cell_inputs_local[cell_id]?.code ?? state.notebook.cell_inputs[cell_id].code)
).length,
// integer
numMarkdowns: cells.filter((c) => first_line(c).startsWith('md"')).length,
numMarkdowns: cell_inputs_local.filter((c) => first_line(c).startsWith('md"')).length,
// integer
numBinds: sum(cells.map((c) => count_matches(/\@bind/g, c.local_code.body))),
numBinds: sum(cell_inputs_local.map((c) => count_matches(/\@bind/g, c.code))),
// integer
numBegins: cells.filter((c) => first_line(c).endsWith("begin")).length,
numBegins: cell_inputs_local.filter((c) => first_line(c).endsWith("begin")).length,
// integer
numLets: cells.filter((c) => first_line(c).endsWith("let")).length,
numLets: cell_inputs_local.filter((c) => first_line(c).endsWith("let")).length,
// integer
cellSizes: value_counts(cells.map((c) => count_matches(/\n/g, c.local_code.body) + 1)),
cellSizes: value_counts(cell_inputs_local.map((c) => count_matches(/\n/g, c.code) + 1)),
// {numLines: numCells, ...}
// e.g. {1: 28, 3: 14, 5: 7, 7: 1, 12: 1, 14: 1}
runtimes: value_counts(cells.map((c) => Math.floor(Math.log10(c.runtime + 1)))),
runtimes: value_counts(cell_results.map((c) => Math.floor(Math.log10(c.runtime + 1)))),
// {runtime: numCells, ...}
// where `runtime` is log10, rounded
// e.g. {1: 28, 3: 14, 5: 7, 7: 1, 12: 1, 14: 1}
Expand All @@ -50,6 +64,7 @@ export const finalize_statistics = async (state, client, counter_statistics) =>
// string, e.g. "v0.7.10"
// versionJulia: client.julia_version,
// // string, e.g. "v1.0.5"
// @ts-ignore
timestamp: firebase.firestore.Timestamp.now(),
// timestamp (ms)
screenWidthApprox: 100 * Math.round(document.body.clientWidth / 100),
Expand Down Expand Up @@ -94,11 +109,13 @@ const feedbackdb = {
instance: null,
}
const init_firebase = () => {
// @ts-ignore
firebase.initializeApp({
apiKey: "AIzaSyC0DqEcaM8AZ6cvApXuNcNU2RgZZOj7F68",
authDomain: "localhost",
projectId: "pluto-feedback",
})
// @ts-ignore
feedbackdb.instance = firebase.firestore()
}

Expand All @@ -111,7 +128,9 @@ export const init_feedback = () => {

timeout_promise(
feedbackdb.instance.collection("feedback").add({
// @ts-ignore
feedback: new FormData(e.target).get("opinion"),
// @ts-ignore
timestamp: firebase.firestore.Timestamp.now(),
email: email ? email : "",
}),
Expand All @@ -121,6 +140,7 @@ export const init_feedback = () => {
let message = "Submitted. Thank you for your feedback! 💕"
console.log(message)
alert(message)
// @ts-ignore
feedbackform.querySelector("#opinion").value = ""
})
.catch((error) => {
Expand Down
1 change: 1 addition & 0 deletions frontend/common/NodejsCompatibilityPolyfill.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-ignore
window.process = {
env: {
NODE_ENV: "production",
Expand Down
Loading