Merge pull request #946 from hgiesel/dispatchtype
Correctly type createEventDispatch and dispatch
This commit is contained in:
commit
687e0b070b
@ -1,6 +1,6 @@
|
|||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import { RevlogRange, GraphRange } from "./graph-helpers";
|
import { RevlogRange, GraphRange } from "./graph-helpers";
|
||||||
import type { TableDatum } from "./graph-helpers";
|
import type { TableDatum, SearchEventMap } from "./graph-helpers";
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
import type { HistogramData } from "./histogram-graph";
|
import type { HistogramData } from "./histogram-graph";
|
||||||
import { gatherData, buildHistogram } from "./added";
|
import { gatherData, buildHistogram } from "./added";
|
||||||
@ -21,7 +21,7 @@
|
|||||||
let graphRange: GraphRange = GraphRange.Month;
|
let graphRange: GraphRange = GraphRange.Month;
|
||||||
let { browserLinksSupported } = preferences;
|
let { browserLinksSupported } = preferences;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher<SearchEventMap>();
|
||||||
|
|
||||||
let addedData: GraphData | null = null;
|
let addedData: GraphData | null = null;
|
||||||
$: if (sourceData) {
|
$: if (sourceData) {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
import NoDataOverlay from "./NoDataOverlay.svelte";
|
import NoDataOverlay from "./NoDataOverlay.svelte";
|
||||||
import AxisTicks from "./AxisTicks.svelte";
|
import AxisTicks from "./AxisTicks.svelte";
|
||||||
import { defaultGraphBounds, RevlogRange } from "./graph-helpers";
|
import { defaultGraphBounds, RevlogRange } from "./graph-helpers";
|
||||||
|
import type { SearchEventMap } from "./graph-helpers";
|
||||||
import { gatherData, renderCalendar } from "./calendar";
|
import { gatherData, renderCalendar } from "./calendar";
|
||||||
import type { PreferenceStore } from "./preferences";
|
import type { PreferenceStore } from "./preferences";
|
||||||
import type { GraphData } from "./calendar";
|
import type { GraphData } from "./calendar";
|
||||||
@ -16,7 +17,7 @@
|
|||||||
export let nightMode: boolean;
|
export let nightMode: boolean;
|
||||||
|
|
||||||
let { calendarFirstDayOfWeek } = preferences;
|
let { calendarFirstDayOfWeek } = preferences;
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher<SearchEventMap>();
|
||||||
|
|
||||||
let graphData: GraphData | null = null;
|
let graphData: GraphData | null = null;
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import { createEventDispatcher } from "svelte";
|
import { createEventDispatcher } from "svelte";
|
||||||
import { defaultGraphBounds } from "./graph-helpers";
|
import { defaultGraphBounds } from "./graph-helpers";
|
||||||
|
import type { SearchEventMap } from "./graph-helpers";
|
||||||
import { gatherData, renderCards } from "./card-counts";
|
import { gatherData, renderCards } from "./card-counts";
|
||||||
import type { GraphData, TableDatum } from "./card-counts";
|
import type { GraphData, TableDatum } from "./card-counts";
|
||||||
import type { PreferenceStore } from "./preferences";
|
import type { PreferenceStore } from "./preferences";
|
||||||
@ -12,7 +13,7 @@
|
|||||||
export let preferences: PreferenceStore;
|
export let preferences: PreferenceStore;
|
||||||
|
|
||||||
let { cardCountsSeparateInactive, browserLinksSupported } = preferences;
|
let { cardCountsSeparateInactive, browserLinksSupported } = preferences;
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher<SearchEventMap>();
|
||||||
|
|
||||||
let svg = null as HTMLElement | SVGElement | null;
|
let svg = null as HTMLElement | SVGElement | null;
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
import type pb from "anki/backend_proto";
|
import type pb from "anki/backend_proto";
|
||||||
import HistogramGraph from "./HistogramGraph.svelte";
|
import HistogramGraph from "./HistogramGraph.svelte";
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
import type { TableDatum } from "./graph-helpers";
|
import type { TableDatum, SearchEventMap } from "./graph-helpers";
|
||||||
import TableData from "./TableData.svelte";
|
import TableData from "./TableData.svelte";
|
||||||
import { createEventDispatcher } from "svelte";
|
import { createEventDispatcher } from "svelte";
|
||||||
import type { PreferenceStore } from "./preferences";
|
import type { PreferenceStore } from "./preferences";
|
||||||
@ -13,7 +13,7 @@
|
|||||||
export let i18n: I18n;
|
export let i18n: I18n;
|
||||||
export let preferences: PreferenceStore;
|
export let preferences: PreferenceStore;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher<SearchEventMap>();
|
||||||
|
|
||||||
let histogramData = null as HistogramData | null;
|
let histogramData = null as HistogramData | null;
|
||||||
let tableData: TableDatum[] = [];
|
let tableData: TableDatum[] = [];
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
import type { HistogramData } from "./histogram-graph";
|
import type { HistogramData } from "./histogram-graph";
|
||||||
import { GraphRange, RevlogRange } from "./graph-helpers";
|
import { GraphRange, RevlogRange } from "./graph-helpers";
|
||||||
import type { TableDatum } from "./graph-helpers";
|
import type { TableDatum, SearchEventMap } from "./graph-helpers";
|
||||||
import { gatherData, buildHistogram } from "./future-due";
|
import { gatherData, buildHistogram } from "./future-due";
|
||||||
import type { GraphData } from "./future-due";
|
import type { GraphData } from "./future-due";
|
||||||
import type pb from "anki/backend_proto";
|
import type pb from "anki/backend_proto";
|
||||||
@ -16,7 +16,7 @@
|
|||||||
export let i18n: I18n;
|
export let i18n: I18n;
|
||||||
export let preferences: PreferenceStore;
|
export let preferences: PreferenceStore;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher<SearchEventMap>();
|
||||||
|
|
||||||
let graphData = null as GraphData | null;
|
let graphData = null as GraphData | null;
|
||||||
let histogramData = null as HistogramData | null;
|
let histogramData = null as HistogramData | null;
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
import type { IntervalGraphData } from "./intervals";
|
import type { IntervalGraphData } from "./intervals";
|
||||||
import type pb from "anki/backend_proto";
|
import type pb from "anki/backend_proto";
|
||||||
import HistogramGraph from "./HistogramGraph.svelte";
|
import HistogramGraph from "./HistogramGraph.svelte";
|
||||||
import type { TableDatum } from "./graph-helpers";
|
import type { TableDatum, SearchEventMap } from "./graph-helpers";
|
||||||
import TableData from "./TableData.svelte";
|
import TableData from "./TableData.svelte";
|
||||||
import { createEventDispatcher } from "svelte";
|
import { createEventDispatcher } from "svelte";
|
||||||
import type { PreferenceStore } from "./preferences";
|
import type { PreferenceStore } from "./preferences";
|
||||||
@ -19,7 +19,7 @@
|
|||||||
export let i18n: I18n;
|
export let i18n: I18n;
|
||||||
export let preferences: PreferenceStore;
|
export let preferences: PreferenceStore;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher<SearchEventMap>();
|
||||||
|
|
||||||
let intervalData: IntervalGraphData | null = null;
|
let intervalData: IntervalGraphData | null = null;
|
||||||
let histogramData = null as HistogramData | null;
|
let histogramData = null as HistogramData | null;
|
||||||
|
@ -10,13 +10,17 @@
|
|||||||
Custom = 3,
|
Custom = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpdateEventMap = {
|
||||||
|
update: { days: number; search: string; searchRange: SearchRange };
|
||||||
|
};
|
||||||
|
|
||||||
export let i18n: I18n;
|
export let i18n: I18n;
|
||||||
export let active: boolean;
|
export let active: boolean;
|
||||||
|
|
||||||
export let days: number;
|
export let days: number;
|
||||||
export let search: string;
|
export let search: string;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher<UpdateEventMap>();
|
||||||
|
|
||||||
let revlogRange = daysToRevlogRange(days);
|
let revlogRange = daysToRevlogRange(days);
|
||||||
let searchRange: SearchRange =
|
let searchRange: SearchRange =
|
||||||
|
@ -14,7 +14,7 @@ import { interpolateBlues } from "d3-scale-chromatic";
|
|||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
import { dayLabel } from "anki/time";
|
import { dayLabel } from "anki/time";
|
||||||
import { GraphRange } from "./graph-helpers";
|
import { GraphRange } from "./graph-helpers";
|
||||||
import type { TableDatum } from "./graph-helpers";
|
import type { TableDatum, SearchDispatch } from "./graph-helpers";
|
||||||
|
|
||||||
export interface GraphData {
|
export interface GraphData {
|
||||||
daysAdded: number[];
|
daysAdded: number[];
|
||||||
@ -43,7 +43,7 @@ export function buildHistogram(
|
|||||||
data: GraphData,
|
data: GraphData,
|
||||||
range: GraphRange,
|
range: GraphRange,
|
||||||
i18n: I18n,
|
i18n: I18n,
|
||||||
dispatch: any,
|
dispatch: SearchDispatch,
|
||||||
browserLinksSupported: boolean
|
browserLinksSupported: boolean
|
||||||
): [HistogramData | null, TableDatum[]] {
|
): [HistogramData | null, TableDatum[]] {
|
||||||
// get min/max
|
// get min/max
|
||||||
|
@ -12,7 +12,12 @@ import "d3-transition";
|
|||||||
import { select, mouse } from "d3-selection";
|
import { select, mouse } from "d3-selection";
|
||||||
import { scaleLinear, scaleSequentialSqrt } from "d3-scale";
|
import { scaleLinear, scaleSequentialSqrt } from "d3-scale";
|
||||||
import { showTooltip, hideTooltip } from "./tooltip";
|
import { showTooltip, hideTooltip } from "./tooltip";
|
||||||
import { GraphBounds, setDataAvailable, RevlogRange } from "./graph-helpers";
|
import {
|
||||||
|
GraphBounds,
|
||||||
|
setDataAvailable,
|
||||||
|
RevlogRange,
|
||||||
|
SearchDispatch,
|
||||||
|
} from "./graph-helpers";
|
||||||
import {
|
import {
|
||||||
timeDay,
|
timeDay,
|
||||||
timeYear,
|
timeYear,
|
||||||
@ -82,7 +87,7 @@ export function renderCalendar(
|
|||||||
svgElem: SVGElement,
|
svgElem: SVGElement,
|
||||||
bounds: GraphBounds,
|
bounds: GraphBounds,
|
||||||
sourceData: GraphData,
|
sourceData: GraphData,
|
||||||
dispatch: any,
|
dispatch: SearchDispatch,
|
||||||
targetYear: number,
|
targetYear: number,
|
||||||
i18n: I18n,
|
i18n: I18n,
|
||||||
nightMode: boolean,
|
nightMode: boolean,
|
||||||
|
@ -13,7 +13,7 @@ import { CardType } from "anki/cards";
|
|||||||
import type { HistogramData } from "./histogram-graph";
|
import type { HistogramData } from "./histogram-graph";
|
||||||
import { interpolateRdYlGn } from "d3-scale-chromatic";
|
import { interpolateRdYlGn } from "d3-scale-chromatic";
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
import type { TableDatum } from "./graph-helpers";
|
import type { TableDatum, SearchDispatch } from "./graph-helpers";
|
||||||
|
|
||||||
export interface GraphData {
|
export interface GraphData {
|
||||||
eases: number[];
|
eases: number[];
|
||||||
@ -40,7 +40,7 @@ function makeQuery(start: number, end: number): string {
|
|||||||
export function prepareData(
|
export function prepareData(
|
||||||
data: GraphData,
|
data: GraphData,
|
||||||
i18n: I18n,
|
i18n: I18n,
|
||||||
dispatch: any,
|
dispatch: SearchDispatch,
|
||||||
browserLinksSupported: boolean
|
browserLinksSupported: boolean
|
||||||
): [HistogramData | null, TableDatum[]] {
|
): [HistogramData | null, TableDatum[]] {
|
||||||
// get min/max
|
// get min/max
|
||||||
@ -49,7 +49,7 @@ export function prepareData(
|
|||||||
return [null, []];
|
return [null, []];
|
||||||
}
|
}
|
||||||
const total = allEases.length;
|
const total = allEases.length;
|
||||||
const [_xMin, origXMax] = extent(allEases);
|
const [, origXMax] = extent(allEases);
|
||||||
let xMax = origXMax;
|
let xMax = origXMax;
|
||||||
const xMin = 130;
|
const xMin = 130;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ import { interpolateGreens } from "d3-scale-chromatic";
|
|||||||
import { dayLabel } from "anki/time";
|
import { dayLabel } from "anki/time";
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
import { GraphRange } from "./graph-helpers";
|
import { GraphRange } from "./graph-helpers";
|
||||||
import type { TableDatum } from "./graph-helpers";
|
import type { TableDatum, SearchDispatch } from "./graph-helpers";
|
||||||
|
|
||||||
export interface GraphData {
|
export interface GraphData {
|
||||||
dueCounts: Map<number, number>;
|
dueCounts: Map<number, number>;
|
||||||
@ -87,7 +87,7 @@ export function buildHistogram(
|
|||||||
range: GraphRange,
|
range: GraphRange,
|
||||||
backlog: boolean,
|
backlog: boolean,
|
||||||
i18n: I18n,
|
i18n: I18n,
|
||||||
dispatch: any,
|
dispatch: SearchDispatch,
|
||||||
browserLinksSupported: boolean
|
browserLinksSupported: boolean
|
||||||
): FutureDueOut {
|
): FutureDueOut {
|
||||||
const output = { histogramData: null, tableData: [] };
|
const output = { histogramData: null, tableData: [] };
|
||||||
|
@ -118,3 +118,9 @@ export interface TableDatum {
|
|||||||
label: string;
|
label: string;
|
||||||
value: string;
|
value: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type SearchEventMap = { search: { query: string } };
|
||||||
|
export type SearchDispatch = <EventKey extends Extract<keyof SearchEventMap, string>>(
|
||||||
|
type: EventKey,
|
||||||
|
detail: SearchEventMap[EventKey]
|
||||||
|
) => void;
|
||||||
|
@ -13,7 +13,7 @@ import { CardType } from "anki/cards";
|
|||||||
import type { HistogramData } from "./histogram-graph";
|
import type { HistogramData } from "./histogram-graph";
|
||||||
import { interpolateBlues } from "d3-scale-chromatic";
|
import { interpolateBlues } from "d3-scale-chromatic";
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
import type { TableDatum } from "./graph-helpers";
|
import type { TableDatum, SearchDispatch } from "./graph-helpers";
|
||||||
import { timeSpan } from "anki/time";
|
import { timeSpan } from "anki/time";
|
||||||
|
|
||||||
export interface IntervalGraphData {
|
export interface IntervalGraphData {
|
||||||
@ -71,7 +71,7 @@ export function prepareIntervalData(
|
|||||||
data: IntervalGraphData,
|
data: IntervalGraphData,
|
||||||
range: IntervalRange,
|
range: IntervalRange,
|
||||||
i18n: I18n,
|
i18n: I18n,
|
||||||
dispatch: any,
|
dispatch: SearchDispatch,
|
||||||
browserLinksSupported: boolean
|
browserLinksSupported: boolean
|
||||||
): [HistogramData | null, TableDatum[]] {
|
): [HistogramData | null, TableDatum[]] {
|
||||||
// get min/max
|
// get min/max
|
||||||
|
Loading…
Reference in New Issue
Block a user