Repository navigation
feat: destroy(), cancellable fades, honest types and tsrs type checking - #81
Merged
Merged
Conversation
Records every addEventListener/removeEventListener on the page, then checks that destroy() removes the container and each listener the picker added (target, document, anchors, drag, in-flight drag), that a destroyed picker ignores focus, document clicks, anchor clicks, show(), hide() and on(), that a second destroy() is a no-op, that other pickers keep working, and that destroy() from inside open, change and close handlers completes cleanly. Fails on 5.0.1: there is no destroy(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
destroy() removes the document mousedown listener, the target's focus or click listener, the click listeners on every hour and minute anchor, and the drag listeners, including the document mousemove/mouseup of a drag in progress (handleDrag now returns a teardown). It clears every mitt handler, cancels the pending fade frame and removes the container. After destroy(), show(), hide() and on() are no-ops, and a second destroy() does nothing. The README documents destroy() and tells #52 readers to call it on the old picker before creating one for a replaced input. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fade() returns only its first requestAnimationFrame id, so neither destroy() nor a later show()/hide() can stop a fade after its first frame. The tests destroy a picker mid fade-in and mid fade-out and require the opacity to stay put for 10 more frames, and call show() during a fade-out and hide() during a fade-in, requiring the state of the last call. On 5.0.1 opacity keeps changing after destroy(), and a show() during a fade-out ends hidden in Chromium. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fade() returned only its first requestAnimationFrame id, and each later frame replaced a local id, so cancelAnimationFrame(requestAnimationId) stopped nothing after the first frame. fade() now reports every frame it schedules through onFrame, which keeps picker.requestAnimationId current. show() and hide() cancel the running fade before starting their own, and destroy() cancels it outright. triggerShow no longer cancels separately, since show() does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The constructor built the picker object with null placeholders and 12 @ts-expect-error comments, and drag.ts started from an empty handler object under a 13th. Now: - createStructure() takes the options, so the DOM is built first and the picker object is created complete. The drag header is checked with instanceof instead of a non-null assertion, and the drag coordinates start at 0 (only read after a mousedown sets them). - handleDrag() takes its start/move/end handlers as an argument and returns the teardown. - fade() emits its internal events without `as keyof EmitterEvents`. - Picker['hour'] and Picker['minute'], and so the change payload, are declared string | null. Runtime is unchanged: both stay null until picked, which the declarations used to hide. The test harness and the README say so. No suppressions, assertions or non-null assertions remain in src. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ond pass As in ol-contextmenu (#290, PR #316): - tsrs 7.1.0-beta.tsrs2, pinned exactly, is the primary checker through its own tsrs bin. TypeScript 7 runs as a labelled second pass by path. The TypeScript 6 declaration tooling is unchanged. - check:typecheckers fails the gate unless tsrs matches the exact pin and the second pass is TypeScript 7. - check-consumers.mjs compiles the packed consumer under bundler and nodenext resolution with both checkers. - check:typecheck-parity (outside verify, needs a build) shows both pass the real project and consumer, and reject planted errors in src/main.ts (TS2322) and in the consumer (TS2322, and TS18047 from the new nullable hour) with the same file, line, column and code. - With tsrs installed, oxlint 1.93 runs tsrs-lint instead of tsgolint, so oxlint-tsgolint is removed. Lint findings are unchanged (0), and a bad file gives identical findings under both backends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
mitt's emit() iterates a copy of the handler list, so clearing it in destroy() does not stop later handlers of the same emission. The test registers a destroying handler first and a recording handler second for open, change and close, and requires the second never to run. Fails at 6d5fc4d: all three recorders run (review round 1, #802). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
on() now registers a wrapper that checks the destroyed flag when it is called, so a handler later in the same emission does not run after an earlier one called destroy(). mitt's emit() iterates a copy of the handler list, which emitter.all.clear() alone cannot stop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements spec #757 (T778):
destroy(), cancellable fades, honest types, and tsrs type checking. Next release expected: 5.1.0.versionis untouched.Commits
5f89d71test: destroy() tears a picker down (failing)5738994feat: add destroy()8534afatest: fades stop on destroy() and on a later show()/hide() (failing)9114b28fix: let destroy(), show() and hide() stop a fade at any frame7e898aarefactor(types): build the picker complete and declare null selections6d5fc4dbuild(types): type check with pinned tsrs, TypeScript 7 as second passThe two test commits were made with
HUSKY=0, because the pre-commit hook runsnpm test. Lint, typecheck and format were run by hand for both.1.
destroy()Test first (
tests/destroy.spec.ts, 6 tests × 3 projects).EventTarget.prototype.add/removeEventListenerbefore creating pickers. That counts the listeners actually attached, not just whether the DOM is gone.destroy(), every listener the picker added is gone, as is the containershow(),hide()and a lateon()all do nothing, with no page errorsdestroy()is a no-opmousemove/mouseup, and a later move doesn't move the containerdestroy()called from insideopen,changeandclosehandlers leaves 0 listeners and no errors5f89d71, all 18 runs fail withdestroy is not a function.What
destroy()does:handleDragnow returns, which also removes an in-progress drag's document listenersshow(),hide()andon()no-ops afterwardsThe README documents
destroy(), and its #52 paragraph now says to call it on the old picker before creating a new one.2. Fade cancellation
The bug:
fade()returned only its firstrequestAnimationFrameid, so cancelling did nothing after the first frame.show()never cancelled a running fade, so ashow()during a fade-out ended hidden.Test first (
tests/fade.spec.ts, 4 tests × 3).destroy(), both mid fade-in and mid fade-outshow()during a fade-out ends shownhide()during a fade-in ends hidden8534afa, 8 of 12 runs fail: both destroy cases in all 3 projects, and show-during-fade-out in both Chromium projects. hide-during-fade-in passes even before the fix, because the fade-in finishes first and the fade-out then completes. It stays as a check on the fixed behavior.Fix:
fade()reports every frame it schedules throughonFrame, which keepspicker.requestAnimationIdcurrent.show()andhide()go throughstartFade(), which cancels the running fade first, anddestroy()cancels it outright. The exportedPickertype is unchanged.3. Honest types
Suppressions: all 13
@ts-expect-errorare gone (12 inmain.ts, 1 indrag.ts). Noas, non-null assertion or suppression is left insrc/.How:
createStructure()takes the options, so the DOM is built first andpickeris created complete. The drag header is checked withinstanceof.handleDrag()takes its handlers as an argument.as keyof EmitterEventscasts infade()were unnecessary and are gone.Contract:
Picker['hour'],Picker['minute'], and so thechangepayload, are declaredstring | null. At runtime both arenulluntil picked, as before. The README now says so. The test harness type follows, with no runtime change.Public API vs 5.0.1: comparing the built
dist/timepicker.d.tswith the published 5.0.1:The only other lines are five new
privatedeclarations (destroyed,releaseDrag,targetEvent,removeDomListeners,startFade), which TypeScript emits for private members. They aren't callable from outside.Runtime unchanged: the existing 45 tests and the packed Chromium/Firefox consumer checks pass.
4. tsrs
Same shape as ol-contextmenu PR #316:
Pin:
tsrsis exactly7.1.0-beta.tsrs2, still the newest build. Upstream dropped itsnextdist-tag on 2026-11-17, solatestnow points to the older0.25.0-ts7.1.0-beta. The version is not deprecated.Scripts:
typecheck=check:typecheckers→typecheck:tsrs→typecheck:ts7. TypeScript 7 runs by path, because.bin/tscis@typescript/typescript6's, whose declaration tooling is unchanged.Guard: exits 1 on a range pin (
^7.1.0-beta.tsrs2) and on a mismatched pin (0.25.0-ts7.1.0-beta); both tried by hand.Consumers:
check-consumers.mjscompiles the packed consumer with tsrs and TypeScript 7, under both bundler and nodenext.Parity:
npm run check:typecheck-parityruns outsideverifyand needs a build.src/main.ts+theme: 'neon'lang: 'xx',evt.hour.padStart(…)'evt.hour' is possibly 'null'at (24,19)Message text is identical too. Exit codes on errors differ (tsrs 2, TS7 1), and both fail.
Lint backend: oxlint 1.93 picks
tsrs-lintonce tsrs is installed..bin/tsrs-lintwith a stub that exits 3 makes lint fail with the stub's message. Replacing.bin/tsgolintleaves lint passing.no-floating-promises,await-thenable,no-unnecessary-type-assertion,no-redundant-type-constituents,require-await,require-array-sort-compare) gives identical findings undertsrs-lintand undertsgolintforced withOXLINT_TSGOLINT_PATH.oxlint-tsgolintis no longer used, so it is removed.Gate
After
rm -rf node_modules dist && npm ci(Node 26.13.1, npm 12.2.2),npm run verifyexits 0:npm auditreports 0 vulnerabilities.🤖 Generated with Claude Code