Skip to content

Commit

Permalink
dev: Add docs&types&autocomplete for lodash import yay (fonsp#2135)
Browse files Browse the repository at this point in the history
* Add types for lodash import yay

* Update TypeScriptCheck.yml

* type fixes thanksss
  • Loading branch information
fonsp authored Jun 1, 2022
1 parent 24d2e05 commit 5ea8939
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/TypeScriptCheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ jobs:

- run: npm install typescript -g

- run: npm install
working-directory: frontend

- name: Run TypeScript checks on frontend/
run: tsc --noEmit --strictNullChecks false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ node_modules
frontend/dist
.net
net
frontend/package-lock.json
2 changes: 1 addition & 1 deletion frontend/components/CellInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ export const CellInput = ({
if (lines_wrapper_dom_node) {
const lines_wrapper_resize_observer = new ResizeObserver(() => {
const line_nodes = lines_wrapper_dom_node.children
const tops = _.map(line_nodes, (c) => c.offsetTop)
const tops = _.map(line_nodes, (c) => /** @type{HTMLElement} */ (c).offsetTop)
const diffs = tops.slice(1).map((y, i) => y - tops[i])
const heights = [...diffs, 15]
on_line_heights(heights)
Expand Down
9 changes: 3 additions & 6 deletions frontend/components/RecordingUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,19 +300,16 @@ export const RecordingPlaybackUI = ({ launch_params, initializing, apply_noteboo

let new_timestamp = audio.currentTime
let forward = new_timestamp >= current_state_timestamp_ref.current
/**
* @param {T} x @template T @return {T}
*/
let directed = (x) => (forward ? x : _.reverse(x))
let directed = forward ? _.identity : _.reverse

let lower = Math.min(current_state_timestamp_ref.current, new_timestamp)
let upper = Math.max(current_state_timestamp_ref.current, new_timestamp)

let scrolls_in_time_window = deserialized.scrolls.filter(([t, s]) => lower < t && t <= upper)
if (scrolls_in_time_window.length > 0) {
let scroll_state = _.last(directed(scrolls_in_time_window))[1]
let scroll_state = _.last(directed(scrolls_in_time_window))?.[1]

on_scroll(scroll_state)
if (scroll_state) on_scroll(scroll_state)
}

let steps_in_current_direction = forward ? deserialized.steps : computed_reverse_patches_ref.current
Expand Down
2 changes: 2 additions & 0 deletions frontend/imports/lodash.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import _ from "lodash-es"
export default _
6 changes: 6 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"devDependencies": {
"@types/lodash": "^4.14.182",
"@types/lodash-es": "^4.17.6"
}
}

0 comments on commit 5ea8939

Please sign in to comment.