mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-06-08 14:11:56 -07:00
websites: restructured
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@
|
||||
"**/solidjs-signals/*/dist/prod.js",
|
||||
"uFuzzy.mjs",
|
||||
"lightweight-charts.standalone.production.mjs",
|
||||
"scripts/packages",
|
||||
// "scripts/packages",
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
|
||||
+5
-8
@@ -1,14 +1,13 @@
|
||||
# TODO
|
||||
|
||||
- __CRATES__
|
||||
- _BUNDLER_
|
||||
- _CLI_
|
||||
- launch
|
||||
- if first, test read/write speed, add warning if too low (<2gb/s)
|
||||
- check available disk space
|
||||
- pull latest version and notify if out of date
|
||||
- add custom path support for config.toml
|
||||
- maybe add bitcoind download and launch support
|
||||
- via: https://github.com/rust-bitcoin/corepc/blob/master/node
|
||||
- _COMPUTER_
|
||||
- **add rollback of states (in stateful)**
|
||||
- add support for per index computation
|
||||
@@ -39,6 +38,8 @@
|
||||
- https://checkonchain.com
|
||||
- https://researchbitcoin.net/exciting-update-coming-to-the-bitcoin-lab/
|
||||
- https://mempool.space/research
|
||||
- _ERROR_
|
||||
- _FETCHER_
|
||||
- _INDEXER_
|
||||
- parse only the needed block number instead the last 100 blocks
|
||||
- maybe using https://developer.bitcoin.org/reference/rpc/getblockhash.html
|
||||
@@ -65,9 +66,8 @@
|
||||
- example: from -10,000 count 10, won’t work if underlying vec isn’t 10k or more long
|
||||
- _LOGGER_
|
||||
- remove colors from file
|
||||
- _MCP_
|
||||
- _PARSER_
|
||||
- Stateless
|
||||
- if less than X (10 maybe ?) get block using rpc instead of parsing the block files
|
||||
- _SERVER_
|
||||
- api
|
||||
- copy mempool's rest api
|
||||
@@ -93,7 +93,6 @@
|
||||
- _STORE_
|
||||
- save height and version in one file
|
||||
- _STRUCTS_
|
||||
- remove `checked_sub` trait ? (checked with the `dev` profile)
|
||||
- __DOCS__
|
||||
- _README_
|
||||
- add a comparison table with alternatives
|
||||
@@ -102,7 +101,6 @@
|
||||
- add faq
|
||||
- __WEBSITES__
|
||||
- _PACKAGES_
|
||||
- move packages from `bitview` to `/packages` or `/websites/packages` or else
|
||||
- move the fetching logic from `bitview` website to an independent `brk` package which could be published to npm
|
||||
- https://www.npmjs.com/package/@mempool/mempool.js
|
||||
- auto publish with github actions
|
||||
@@ -145,9 +143,8 @@
|
||||
- by having a global state
|
||||
- font:
|
||||
- https://fonts.google.com/specimen/Space+Mono
|
||||
|
||||
- keep as many files as possible [under 14kb](https://endtimes.dev/why-your-website-should-be-under-14kb-in-size/)
|
||||
- No classes: https://news.ycombinator.com/item?id=45287155
|
||||
- [No classes](https://news.ycombinator.com/item?id=45287155)
|
||||
- __GLOBAL__
|
||||
- check `TODO`s in codebase
|
||||
- rename `output` to `txout` or `vout`, `input` to `txin` or `vin`
|
||||
|
||||
+1085
-517
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,584 @@
|
||||
// @ts-check
|
||||
|
||||
const keyPrefix = "chart";
|
||||
const ONE_BTC_IN_SATS = 100_000_000;
|
||||
const AUTO = "auto";
|
||||
const LINE = "line";
|
||||
const CANDLE = "candle";
|
||||
|
||||
/**
|
||||
* @typedef {"timestamp" | "date" | "week" | "d.epoch" | "month" | "quarter" | "semester" | "year" | "decade" } SerializedChartableIndex
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {Object} args
|
||||
* @param {Colors} args.colors
|
||||
* @param {CreateChartElement} args.createChartElement
|
||||
* @param {Accessor<ChartOption>} args.option
|
||||
* @param {Signals} args.signals
|
||||
* @param {Utilities} args.utils
|
||||
* @param {WebSockets} args.webSockets
|
||||
* @param {Elements} args.elements
|
||||
* @param {Env} args.env
|
||||
* @param {VecsResources} args.vecsResources
|
||||
* @param {VecIdToIndexes} args.vecIdToIndexes
|
||||
* @param {Packages} args.packages
|
||||
*/
|
||||
export function init({
|
||||
colors,
|
||||
elements,
|
||||
createChartElement,
|
||||
option,
|
||||
signals,
|
||||
utils,
|
||||
env,
|
||||
webSockets,
|
||||
vecsResources,
|
||||
vecIdToIndexes,
|
||||
packages,
|
||||
}) {
|
||||
elements.charts.append(utils.dom.createShadow("left"));
|
||||
elements.charts.append(utils.dom.createShadow("right"));
|
||||
|
||||
const { headerElement, headingElement } = utils.dom.createHeader();
|
||||
elements.charts.append(headerElement);
|
||||
|
||||
const { index, fieldset } = createIndexSelector({
|
||||
option,
|
||||
vecIdToIndexes,
|
||||
signals,
|
||||
utils,
|
||||
});
|
||||
|
||||
const TIMERANGE_LS_KEY = signals.createMemo(
|
||||
() => `chart-timerange-${index()}`,
|
||||
);
|
||||
|
||||
let firstRun = true;
|
||||
|
||||
const from = signals.createSignal(/** @type {number | null} */ (null), {
|
||||
save: {
|
||||
...utils.serde.optNumber,
|
||||
keyPrefix: TIMERANGE_LS_KEY,
|
||||
key: "from",
|
||||
serializeParam: firstRun,
|
||||
},
|
||||
});
|
||||
const to = signals.createSignal(/** @type {number | null} */ (null), {
|
||||
save: {
|
||||
...utils.serde.optNumber,
|
||||
keyPrefix: TIMERANGE_LS_KEY,
|
||||
key: "to",
|
||||
serializeParam: firstRun,
|
||||
},
|
||||
});
|
||||
|
||||
const chart = createChartElement({
|
||||
parent: elements.charts,
|
||||
signals,
|
||||
colors,
|
||||
id: "charts",
|
||||
utils,
|
||||
vecsResources,
|
||||
elements,
|
||||
index,
|
||||
timeScaleSetCallback: (unknownTimeScaleCallback) => {
|
||||
// TODO: Although it mostly works in practice, need to make it more robust, there is no guarantee that this runs in order and wait for `from` and `to` to update when `index` and thus `TIMERANGE_LS_KEY` is updated
|
||||
// Need to have the right values before the update
|
||||
|
||||
const from_ = from();
|
||||
const to_ = to();
|
||||
if (from_ !== null && to_ !== null) {
|
||||
chart.inner.timeScale().setVisibleLogicalRange({
|
||||
from: from_,
|
||||
to: to_,
|
||||
});
|
||||
} else {
|
||||
unknownTimeScaleCallback();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
console.log(env.ios, "canShare" in navigator);
|
||||
if (!(env.ios && !("canShare" in navigator))) {
|
||||
const chartBottomRightCanvas = Array.from(
|
||||
chart.inner.chartElement().getElementsByTagName("tr"),
|
||||
).at(-1)?.lastChild?.firstChild?.firstChild;
|
||||
if (chartBottomRightCanvas) {
|
||||
const charts = elements.charts;
|
||||
const domain = window.document.createElement("p");
|
||||
domain.innerText = `${window.location.host}`;
|
||||
domain.id = "domain";
|
||||
const screenshotButton = window.document.createElement("button");
|
||||
screenshotButton.id = "screenshot";
|
||||
const camera = "[ ◉¯]";
|
||||
screenshotButton.innerHTML = camera;
|
||||
screenshotButton.title = "Screenshot";
|
||||
chartBottomRightCanvas.replaceWith(screenshotButton);
|
||||
screenshotButton.addEventListener("click", () => {
|
||||
packages.modernScreenshot().then(async ({ screenshot }) => {
|
||||
charts.dataset.screenshot = "true";
|
||||
charts.append(domain);
|
||||
seriesTypeField.hidden = true;
|
||||
try {
|
||||
await screenshot({
|
||||
element: charts,
|
||||
name: option().path.join("-"),
|
||||
title: option().title,
|
||||
});
|
||||
} catch {}
|
||||
charts.removeChild(domain);
|
||||
seriesTypeField.hidden = false;
|
||||
charts.dataset.screenshot = "false";
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
chart.inner.timeScale().subscribeVisibleLogicalRangeChange(
|
||||
utils.throttle((t) => {
|
||||
if (!t) return;
|
||||
from.set(t.from);
|
||||
to.set(t.to);
|
||||
}, 250),
|
||||
);
|
||||
|
||||
elements.charts.append(fieldset);
|
||||
|
||||
const { field: seriesTypeField, selected: topSeriesType_ } =
|
||||
utils.dom.createHorizontalChoiceField({
|
||||
defaultValue: CANDLE,
|
||||
keyPrefix,
|
||||
key: "seriestype-0",
|
||||
choices: /** @type {const} */ ([AUTO, CANDLE, LINE]),
|
||||
signals,
|
||||
});
|
||||
|
||||
const topSeriesType = signals.createMemo(() => {
|
||||
const topSeriesType = topSeriesType_();
|
||||
if (topSeriesType === AUTO) {
|
||||
const t = to();
|
||||
const f = from();
|
||||
if (!t || !f) return null;
|
||||
const diff = t - f;
|
||||
if (diff / chart.inner.paneSize().width <= 0.5) {
|
||||
return CANDLE;
|
||||
} else {
|
||||
return LINE;
|
||||
}
|
||||
} else {
|
||||
return topSeriesType;
|
||||
}
|
||||
});
|
||||
|
||||
const { field: topUnitField, selected: topUnit } =
|
||||
utils.dom.createHorizontalChoiceField({
|
||||
defaultValue: "usd",
|
||||
keyPrefix,
|
||||
key: "unit-0",
|
||||
choices: /** @type {const} */ ([
|
||||
/** @satisfies {Unit} */ ("usd"),
|
||||
/** @satisfies {Unit} */ ("sats"),
|
||||
]),
|
||||
signals,
|
||||
sorted: true,
|
||||
});
|
||||
|
||||
chart.addFieldsetIfNeeded({
|
||||
id: "charts-unit-0",
|
||||
paneIndex: 0,
|
||||
position: "nw",
|
||||
createChild() {
|
||||
return topUnitField;
|
||||
},
|
||||
});
|
||||
|
||||
const seriesListTop = /** @type {Series[]} */ ([]);
|
||||
const seriesListBottom = /** @type {Series[]} */ ([]);
|
||||
|
||||
/**
|
||||
* @param {Object} params
|
||||
* @param {ISeries} params.iseries
|
||||
* @param {Unit} params.unit
|
||||
* @param {Index} params.index
|
||||
*/
|
||||
function printLatest({ iseries, unit, index }) {
|
||||
const _latest = webSockets.kraken1dCandle.latest();
|
||||
|
||||
if (!_latest) return;
|
||||
|
||||
const latest = { ..._latest };
|
||||
|
||||
if (unit === "sats") {
|
||||
latest.open = Math.floor(ONE_BTC_IN_SATS / latest.open);
|
||||
latest.high = Math.floor(ONE_BTC_IN_SATS / latest.high);
|
||||
latest.low = Math.floor(ONE_BTC_IN_SATS / latest.low);
|
||||
latest.close = Math.floor(ONE_BTC_IN_SATS / latest.close);
|
||||
}
|
||||
|
||||
const last_ = iseries.data().at(-1);
|
||||
if (!last_) return;
|
||||
const last = { ...last_ };
|
||||
|
||||
if ("close" in last) {
|
||||
last.close = latest.close;
|
||||
}
|
||||
if ("value" in last) {
|
||||
last.value = latest.close;
|
||||
}
|
||||
const date = new Date(latest.time * 1000);
|
||||
|
||||
switch (index) {
|
||||
case /** @satisfies {Height} */ (5):
|
||||
case /** @satisfies {DifficultyEpoch} */ (2):
|
||||
case /** @satisfies {HalvingEpoch} */ (4): {
|
||||
if ("close" in last) {
|
||||
last.low = Math.min(last.low, latest.close);
|
||||
last.high = Math.max(last.high, latest.close);
|
||||
}
|
||||
iseries.update(last);
|
||||
break;
|
||||
}
|
||||
case /** @satisfies {DateIndex} */ (0): {
|
||||
iseries.update(last);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if (index === /** @satisfies {WeekIndex} */ (23)) {
|
||||
date.setUTCDate(date.getUTCDate() - ((date.getUTCDay() + 6) % 7));
|
||||
} else if (index === /** @satisfies {MonthIndex} */ (7)) {
|
||||
date.setUTCDate(1);
|
||||
} else if (index === /** @satisfies {QuarterIndex} */ (19)) {
|
||||
const month = date.getUTCMonth();
|
||||
date.setUTCMonth(month - (month % 3), 1);
|
||||
} else if (index === /** @satisfies {SemesterIndex} */ (20)) {
|
||||
const month = date.getUTCMonth();
|
||||
date.setUTCMonth(month - (month % 6), 1);
|
||||
} else if (index === /** @satisfies {YearIndex} */ (24)) {
|
||||
date.setUTCMonth(0, 1);
|
||||
} else if (index === /** @satisfies {DecadeIndex} */ (1)) {
|
||||
date.setUTCFullYear(
|
||||
Math.floor(date.getUTCFullYear() / 10) * 10,
|
||||
0,
|
||||
1,
|
||||
);
|
||||
} else {
|
||||
throw Error("Unsupported");
|
||||
}
|
||||
|
||||
const time = date.valueOf() / 1000;
|
||||
|
||||
if (time === last.time) {
|
||||
if ("close" in last) {
|
||||
last.low = Math.min(last.low, latest.low);
|
||||
last.high = Math.max(last.high, latest.high);
|
||||
}
|
||||
iseries.update(last);
|
||||
} else {
|
||||
latest.time = time;
|
||||
iseries.update(last);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signals.createEffect(option, (option) => {
|
||||
headingElement.innerHTML = option.title;
|
||||
|
||||
const bottomUnits = /** @type {readonly Unit[]} */ (
|
||||
Object.keys(option.bottom)
|
||||
);
|
||||
const { field: bottomUnitField, selected: bottomUnit } =
|
||||
utils.dom.createHorizontalChoiceField({
|
||||
defaultValue: bottomUnits.at(0) || "",
|
||||
keyPrefix,
|
||||
key: "unit-1",
|
||||
choices: bottomUnits,
|
||||
signals,
|
||||
sorted: true,
|
||||
});
|
||||
|
||||
if (bottomUnits.length) {
|
||||
chart.addFieldsetIfNeeded({
|
||||
id: "charts-unit-1",
|
||||
paneIndex: 1,
|
||||
position: "nw",
|
||||
createChild() {
|
||||
return bottomUnitField;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
chart.addFieldsetIfNeeded({
|
||||
id: "charts-seriestype-0",
|
||||
paneIndex: 0,
|
||||
position: "ne",
|
||||
createChild() {
|
||||
return seriesTypeField;
|
||||
},
|
||||
});
|
||||
|
||||
signals.createEffect(index, (index) => {
|
||||
signals.createEffect(
|
||||
() => ({
|
||||
topUnit: topUnit(),
|
||||
topSeriesType: topSeriesType(),
|
||||
}),
|
||||
({ topUnit, topSeriesType }) => {
|
||||
/** @type {Series | undefined} */
|
||||
let series;
|
||||
|
||||
console.log({ topUnit, topSeriesType });
|
||||
|
||||
switch (topUnit) {
|
||||
case "usd": {
|
||||
switch (topSeriesType) {
|
||||
case null:
|
||||
case CANDLE: {
|
||||
series = chart.addCandlestickSeries({
|
||||
vecId: "price_ohlc",
|
||||
name: "Price",
|
||||
unit: topUnit,
|
||||
setDataCallback: printLatest,
|
||||
order: 0,
|
||||
});
|
||||
break;
|
||||
}
|
||||
case LINE: {
|
||||
series = chart.addLineSeries({
|
||||
vecId: "price_close",
|
||||
name: "Price",
|
||||
unit: topUnit,
|
||||
color: colors.default,
|
||||
setDataCallback: printLatest,
|
||||
options: {
|
||||
priceLineVisible: true,
|
||||
lastValueVisible: true,
|
||||
},
|
||||
order: 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "sats": {
|
||||
switch (topSeriesType) {
|
||||
case null:
|
||||
case CANDLE: {
|
||||
series = chart.addCandlestickSeries({
|
||||
vecId: "price_ohlc_in_sats",
|
||||
name: "Price",
|
||||
unit: topUnit,
|
||||
inverse: true,
|
||||
setDataCallback: printLatest,
|
||||
order: 0,
|
||||
});
|
||||
break;
|
||||
}
|
||||
case LINE: {
|
||||
series = chart.addLineSeries({
|
||||
vecId: "price_close_in_sats",
|
||||
name: "Price",
|
||||
unit: topUnit,
|
||||
color: colors.default,
|
||||
setDataCallback: printLatest,
|
||||
options: {
|
||||
priceLineVisible: true,
|
||||
lastValueVisible: true,
|
||||
},
|
||||
order: 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!series) throw Error("Unreachable");
|
||||
|
||||
seriesListTop[0]?.remove();
|
||||
seriesListTop[0] = series;
|
||||
|
||||
signals.createEffect(
|
||||
() => ({
|
||||
latest: webSockets.kraken1dCandle.latest(),
|
||||
hasData: series.hasData(),
|
||||
}),
|
||||
({ latest, hasData }) => {
|
||||
if (!series || !latest || !hasData) return;
|
||||
printLatest({ iseries: series.inner, unit: topUnit, index });
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
[
|
||||
{
|
||||
blueprints: option.top,
|
||||
paneIndex: 0,
|
||||
unit: topUnit,
|
||||
seriesList: seriesListTop,
|
||||
orderStart: 1,
|
||||
legend: chart.legendTop,
|
||||
},
|
||||
{
|
||||
blueprints: option.bottom,
|
||||
paneIndex: 1,
|
||||
unit: bottomUnit,
|
||||
seriesList: seriesListBottom,
|
||||
orderStart: 0,
|
||||
legend: chart.legendBottom,
|
||||
},
|
||||
].forEach(
|
||||
({ blueprints, paneIndex, unit, seriesList, orderStart, legend }) => {
|
||||
signals.createEffect(unit, (unit) => {
|
||||
legend.removeFrom(orderStart);
|
||||
|
||||
seriesList.splice(orderStart).forEach((series) => {
|
||||
series.remove();
|
||||
});
|
||||
|
||||
blueprints[unit]?.forEach((blueprint, order) => {
|
||||
order += orderStart;
|
||||
|
||||
const indexes = /** @type {readonly number[]} */ (
|
||||
vecIdToIndexes[blueprint.key]
|
||||
);
|
||||
|
||||
if (indexes.includes(index)) {
|
||||
switch (blueprint.type) {
|
||||
case "Baseline": {
|
||||
seriesList.push(
|
||||
chart.addBaselineSeries({
|
||||
vecId: blueprint.key,
|
||||
name: blueprint.title,
|
||||
unit,
|
||||
defaultActive: blueprint.defaultActive,
|
||||
paneIndex,
|
||||
options: {
|
||||
...blueprint.options,
|
||||
topLineColor:
|
||||
blueprint.color?.() ?? blueprint.colors?.[0](),
|
||||
bottomLineColor:
|
||||
blueprint.color?.() ?? blueprint.colors?.[1](),
|
||||
},
|
||||
order,
|
||||
}),
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "Histogram": {
|
||||
seriesList.push(
|
||||
chart.addHistogramSeries({
|
||||
vecId: blueprint.key,
|
||||
name: blueprint.title,
|
||||
unit,
|
||||
color: blueprint.color,
|
||||
defaultActive: blueprint.defaultActive,
|
||||
paneIndex,
|
||||
options: blueprint.options,
|
||||
order,
|
||||
}),
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "Candlestick": {
|
||||
throw Error("TODO");
|
||||
}
|
||||
case "Line":
|
||||
case undefined:
|
||||
seriesList.push(
|
||||
chart.addLineSeries({
|
||||
vecId: blueprint.key,
|
||||
color: blueprint.color,
|
||||
name: blueprint.title,
|
||||
unit,
|
||||
defaultActive: blueprint.defaultActive,
|
||||
paneIndex,
|
||||
options: blueprint.options,
|
||||
order,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
firstRun = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} args
|
||||
* @param {Accessor<ChartOption>} args.option
|
||||
* @param {VecIdToIndexes} args.vecIdToIndexes
|
||||
* @param {Signals} args.signals
|
||||
* @param {Utilities} args.utils
|
||||
*/
|
||||
function createIndexSelector({ option, vecIdToIndexes, signals, utils }) {
|
||||
const choices_ = /** @satisfies {SerializedChartableIndex[]} */ ([
|
||||
"timestamp",
|
||||
"date",
|
||||
"week",
|
||||
"d.epoch",
|
||||
"month",
|
||||
"quarter",
|
||||
"semester",
|
||||
"year",
|
||||
// "halving epoch",
|
||||
"decade",
|
||||
]);
|
||||
|
||||
/** @type {Accessor<typeof choices_>} */
|
||||
const choices = signals.createMemo(() => {
|
||||
const o = option();
|
||||
|
||||
if (!Object.keys(o.top).length && !Object.keys(o.bottom).length) {
|
||||
return [...choices_];
|
||||
}
|
||||
const rawIndexes = new Set(
|
||||
[Object.values(o.top), Object.values(o.bottom)]
|
||||
.flat(2)
|
||||
.filter((blueprint) => !blueprint.key.startsWith("constant_"))
|
||||
.map((blueprint) => vecIdToIndexes[blueprint.key])
|
||||
.flat(),
|
||||
);
|
||||
|
||||
const serializedIndexes = [...rawIndexes].flatMap((index) => {
|
||||
const c = utils.serde.chartableIndex.serialize(index);
|
||||
return c ? [c] : [];
|
||||
});
|
||||
|
||||
return /** @type {any} */ (
|
||||
choices_.filter((choice) => serializedIndexes.includes(choice))
|
||||
);
|
||||
});
|
||||
|
||||
const { field, selected } = utils.dom.createHorizontalChoiceField({
|
||||
defaultValue: "date",
|
||||
keyPrefix,
|
||||
key: "index",
|
||||
choices,
|
||||
id: "index",
|
||||
signals,
|
||||
});
|
||||
|
||||
const fieldset = window.document.createElement("fieldset");
|
||||
fieldset.id = "interval";
|
||||
|
||||
const screenshotSpan = window.document.createElement("span");
|
||||
screenshotSpan.innerText = "interval:";
|
||||
fieldset.append(screenshotSpan);
|
||||
|
||||
fieldset.append(field);
|
||||
fieldset.dataset.size = "sm";
|
||||
|
||||
const index = signals.createMemo(() =>
|
||||
utils.serde.chartableIndex.deserialize(selected()),
|
||||
);
|
||||
|
||||
return { fieldset, index };
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* @param {Object} args
|
||||
* @param {Colors} args.colors
|
||||
* @param {LightweightCharts} args.lightweightCharts
|
||||
* @param {CreateChartElement} args.createChartElement
|
||||
* @param {Accessor<ChartOption>} args.option
|
||||
* @param {Signals} args.signals
|
||||
* @param {Utilities} args.utils
|
||||
@@ -15,7 +15,7 @@
|
||||
export function init({
|
||||
colors,
|
||||
elements,
|
||||
lightweightCharts,
|
||||
createChartElement,
|
||||
option,
|
||||
signals,
|
||||
utils,
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
/**
|
||||
* @import { Option, PartialChartOption, ChartOption, AnyPartialOption, ProcessedOptionAddons, OptionsTree, SimulationOption, AnySeriesBlueprint, SeriesType } from "./options"
|
||||
* @import { Valued, SingleValueData, CandlestickData, OHLCTuple, Series, ISeries, HistogramData, LineData, BaselineData, LineSeriesPartialOptions, BaselineSeriesPartialOptions, HistogramSeriesPartialOptions, CandlestickSeriesPartialOptions } from "./packages/lightweight-charts/wrapper"
|
||||
* @import { Valued, SingleValueData, CandlestickData, OHLCTuple, Series, ISeries, HistogramData, LineData, BaselineData, LineSeriesPartialOptions, BaselineSeriesPartialOptions, HistogramSeriesPartialOptions, CandlestickSeriesPartialOptions, CreateChartElement, Chart } from "./chart"
|
||||
* @import * as _ from "./packages/leeoniya-ufuzzy/1.0.19/dist/uFuzzy.d.ts"
|
||||
* @import { SerializedChartableIndex } from "./chart";
|
||||
* @import { SerializedChartableIndex } from "./charts";
|
||||
* @import { Signal, Signals, Accessor } from "./packages/solidjs-signals/wrapper";
|
||||
* @import { DateIndex, DecadeIndex, DifficultyEpoch, Index, HalvingEpoch, Height, MonthIndex, P2PK33AddressIndex, P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2MSOutputIndex, P2AAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex, P2WSHAddressIndex, TxIndex, InputIndex, OutputIndex, VecId, WeekIndex, SemesterIndex, YearIndex, VecIdToIndexes, QuarterIndex, EmptyOutputIndex, OpReturnIndex, UnknownOutputIndex, EmptyAddressIndex, LoadedAddressIndex } from "./bridge/vecs"
|
||||
* @import { Pools, Pool } from "./bridge/pools"
|
||||
@@ -76,11 +76,9 @@ function initPackages() {
|
||||
(d) => d.default,
|
||||
);
|
||||
},
|
||||
async lightweightCharts() {
|
||||
async chart() {
|
||||
return window.document.fonts.ready.then(() =>
|
||||
import("./packages/lightweight-charts/wrapper.js").then(
|
||||
(d) => d.default,
|
||||
),
|
||||
import("./chart.js").then((d) => d.default),
|
||||
);
|
||||
},
|
||||
async leanQr() {
|
||||
@@ -100,7 +98,7 @@ function initPackages() {
|
||||
* @template {keyof typeof imports} K
|
||||
* @param {K} key
|
||||
*/
|
||||
function importPackage(key) {
|
||||
function lazyImport(key) {
|
||||
/** @type {ReturnType<typeof imports[K]> | null} */
|
||||
let packagePromise = null;
|
||||
|
||||
@@ -114,17 +112,15 @@ function initPackages() {
|
||||
}
|
||||
|
||||
return {
|
||||
signals: importPackage("signals"),
|
||||
lightweightCharts: importPackage("lightweightCharts"),
|
||||
leanQr: importPackage("leanQr"),
|
||||
ufuzzy: importPackage("ufuzzy"),
|
||||
modernScreenshot: importPackage("modernScreenshot"),
|
||||
signals: lazyImport("signals"),
|
||||
chart: lazyImport("chart"),
|
||||
leanQr: lazyImport("leanQr"),
|
||||
ufuzzy: lazyImport("ufuzzy"),
|
||||
modernScreenshot: lazyImport("modernScreenshot"),
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @typedef {ReturnType<typeof initPackages>} Packages
|
||||
* @typedef {Awaited<ReturnType<Packages["lightweightCharts"]>>} LightweightCharts
|
||||
* @typedef {ReturnType<LightweightCharts['createChartElement']>} Chart
|
||||
*/
|
||||
|
||||
function createUtils() {
|
||||
@@ -2314,14 +2310,14 @@ function main() {
|
||||
element = elements.explorer;
|
||||
|
||||
if (firstTimeLoadingExplorer) {
|
||||
const lightweightCharts = packages.lightweightCharts();
|
||||
const chartPkg = packages.chart();
|
||||
import("./explorer.js").then(({ init }) =>
|
||||
lightweightCharts.then((lightweightCharts) =>
|
||||
chartPkg.then(({ createChartElement }) =>
|
||||
signals.runWithOwner(owner, () =>
|
||||
init({
|
||||
colors,
|
||||
elements,
|
||||
lightweightCharts,
|
||||
createChartElement,
|
||||
option: /** @type {Accessor<ChartOption>} */ (
|
||||
chartOption
|
||||
),
|
||||
@@ -2345,14 +2341,14 @@ function main() {
|
||||
chartOption.set(option);
|
||||
|
||||
if (firstTimeLoadingChart) {
|
||||
const lightweightCharts = packages.lightweightCharts();
|
||||
import("./chart.js").then(({ init: initChartsElement }) =>
|
||||
lightweightCharts.then((lightweightCharts) =>
|
||||
const chartPkg = packages.chart();
|
||||
import("./charts.js").then(({ init: initChartsElement }) =>
|
||||
chartPkg.then(({ createChartElement }) =>
|
||||
signals.runWithOwner(owner, () =>
|
||||
initChartsElement({
|
||||
colors,
|
||||
elements,
|
||||
lightweightCharts,
|
||||
createChartElement,
|
||||
option: /** @type {Accessor<ChartOption>} */ (
|
||||
chartOption
|
||||
),
|
||||
@@ -2399,14 +2395,14 @@ function main() {
|
||||
simOption.set(option);
|
||||
|
||||
if (firstTimeLoadingSimulation) {
|
||||
const lightweightCharts = packages.lightweightCharts();
|
||||
const chart = packages.chart();
|
||||
import("./simulation.js").then(({ init }) =>
|
||||
lightweightCharts.then((lightweightCharts) =>
|
||||
chart.then(({ createChartElement }) =>
|
||||
signals.runWithOwner(owner, () =>
|
||||
init({
|
||||
colors,
|
||||
elements,
|
||||
lightweightCharts,
|
||||
createChartElement,
|
||||
signals,
|
||||
utils,
|
||||
vecsResources,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* @param {Object} args
|
||||
* @param {Colors} args.colors
|
||||
* @param {LightweightCharts} args.lightweightCharts
|
||||
* @param {CreateChartElement} args.createChartElement
|
||||
* @param {Signals} args.signals
|
||||
* @param {Utilities} args.utils
|
||||
* @param {Elements} args.elements
|
||||
@@ -12,7 +12,7 @@
|
||||
export function init({
|
||||
colors,
|
||||
elements,
|
||||
lightweightCharts,
|
||||
createChartElement,
|
||||
signals,
|
||||
utils,
|
||||
vecsResources,
|
||||
@@ -679,7 +679,7 @@ export function init({
|
||||
|
||||
const index = () => /** @type {DateIndex} */ (0);
|
||||
|
||||
lightweightCharts.createChartElement({
|
||||
createChartElement({
|
||||
index,
|
||||
parent: resultsElement,
|
||||
signals,
|
||||
@@ -724,7 +724,7 @@ export function init({
|
||||
],
|
||||
});
|
||||
|
||||
lightweightCharts.createChartElement({
|
||||
createChartElement({
|
||||
index,
|
||||
parent: resultsElement,
|
||||
signals,
|
||||
@@ -749,7 +749,7 @@ export function init({
|
||||
],
|
||||
});
|
||||
|
||||
lightweightCharts.createChartElement({
|
||||
createChartElement({
|
||||
index,
|
||||
parent: resultsElement,
|
||||
signals,
|
||||
@@ -780,7 +780,7 @@ export function init({
|
||||
],
|
||||
});
|
||||
|
||||
lightweightCharts.createChartElement({
|
||||
createChartElement({
|
||||
index,
|
||||
parent: resultsElement,
|
||||
signals,
|
||||
@@ -804,7 +804,7 @@ export function init({
|
||||
],
|
||||
});
|
||||
|
||||
lightweightCharts.createChartElement({
|
||||
createChartElement({
|
||||
index,
|
||||
parent: resultsElement,
|
||||
signals,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
-1973
File diff suppressed because it is too large
Load Diff
@@ -1,21 +0,0 @@
|
||||
import { Computation, Queue } from "./core/index.js";
|
||||
import type { Effect } from "./core/index.js";
|
||||
export declare class CollectionQueue extends Queue {
|
||||
_collectionType: number;
|
||||
_nodes: Set<Effect>;
|
||||
_disabled: Computation<boolean>;
|
||||
constructor(type: number);
|
||||
run(type: number): void;
|
||||
notify(node: Effect, type: number, flags: number): boolean;
|
||||
}
|
||||
export declare enum BoundaryMode {
|
||||
VISIBLE = "visible",
|
||||
HIDDEN = "hidden"
|
||||
}
|
||||
export declare function createBoundary<T>(fn: () => T, condition: () => BoundaryMode): () => T | undefined;
|
||||
export declare function createSuspense(fn: () => any, fallback: () => any): () => any;
|
||||
export declare function createErrorBoundary<U>(fn: () => any, fallback: (error: unknown, reset: () => void) => U): () => any;
|
||||
export declare function flatten(children: any, options?: {
|
||||
skipNonRendered?: boolean;
|
||||
doNotUnwrap?: boolean;
|
||||
}): any;
|
||||
@@ -1,14 +0,0 @@
|
||||
/**
|
||||
* See https://dev.to/modderme123/super-charging-fine-grained-reactive-performance-47ph
|
||||
* State clean corresponds to a node where all the sources are fully up to date
|
||||
* State check corresponds to a node where some sources (including grandparents) may have changed
|
||||
* State dirty corresponds to a node where the direct parents of a node has changed
|
||||
*/
|
||||
export declare const STATE_CLEAN = 0;
|
||||
export declare const STATE_CHECK = 1;
|
||||
export declare const STATE_DIRTY = 2;
|
||||
export declare const STATE_DISPOSED = 3;
|
||||
export declare const EFFECT_PURE = 0;
|
||||
export declare const EFFECT_RENDER = 1;
|
||||
export declare const EFFECT_USER = 2;
|
||||
export declare const SUPPORTS_PROXY: boolean;
|
||||
@@ -1,157 +0,0 @@
|
||||
/**
|
||||
* Nodes for constructing a graph of reactive values and reactive computations.
|
||||
*
|
||||
* - The graph is acyclic.
|
||||
* - The user inputs new values into the graph by calling .write() on one more computation nodes.
|
||||
* - The user retrieves computed results from the graph by calling .read() on one or more computation nodes.
|
||||
* - The library is responsible for running any necessary computations so that .read() is up to date
|
||||
* with all prior .write() calls anywhere in the graph.
|
||||
* - We call the input nodes 'roots' and the output nodes 'leaves' of the graph here.
|
||||
* - Changes flow from roots to leaves. It would be effective but inefficient to immediately
|
||||
* propagate all changes from a root through the graph to descendant leaves. Instead, we defer
|
||||
* change most change propagation computation until a leaf is accessed. This allows us to
|
||||
* coalesce computations and skip altogether recalculating unused sections of the graph.
|
||||
* - Each computation node tracks its sources and its observers (observers are other
|
||||
* elements that have this node as a source). Source and observer links are updated automatically
|
||||
* as observer computations re-evaluate and call get() on their sources.
|
||||
* - Each node stores a cache state (clean/check/dirty) to support the change propagation algorithm:
|
||||
*
|
||||
* In general, execution proceeds in three passes:
|
||||
*
|
||||
* 1. write() propagates changes down the graph to the leaves
|
||||
* direct children are marked as dirty and their deeper descendants marked as check
|
||||
* (no computations are evaluated)
|
||||
* 2. read() requests that parent nodes updateIfNecessary(), which proceeds recursively up the tree
|
||||
* to decide whether the node is clean (parents unchanged) or dirty (parents changed)
|
||||
* 3. updateIfNecessary() evaluates the computation if the node is dirty (the computations are
|
||||
* executed in root to leaf order)
|
||||
*/
|
||||
import { type Flags } from "./flags.js";
|
||||
import { Owner } from "./owner.js";
|
||||
export interface SignalOptions<T> {
|
||||
id?: string;
|
||||
name?: string;
|
||||
equals?: ((prev: T, next: T) => boolean) | false;
|
||||
pureWrite?: boolean;
|
||||
unobserved?: () => void;
|
||||
}
|
||||
interface SourceType {
|
||||
_observers: ObserverType[] | null;
|
||||
_unobserved?: () => void;
|
||||
_updateIfNecessary: () => void;
|
||||
_stateFlags: Flags;
|
||||
_time: number;
|
||||
}
|
||||
interface ObserverType {
|
||||
_sources: SourceType[] | null;
|
||||
_notify: (state: number, skipQueue?: boolean) => void;
|
||||
_handlerMask: Flags;
|
||||
_notifyFlags: (mask: Flags, newFlags: Flags) => void;
|
||||
_time: number;
|
||||
}
|
||||
/**
|
||||
* Returns the current observer.
|
||||
*/
|
||||
export declare function getObserver(): Computation | null;
|
||||
export declare const UNCHANGED: unique symbol;
|
||||
export type UNCHANGED = typeof UNCHANGED;
|
||||
export declare class Computation<T = any> extends Owner implements SourceType, ObserverType {
|
||||
_sources: SourceType[] | null;
|
||||
_observers: ObserverType[] | null;
|
||||
_value: T | undefined;
|
||||
_error: unknown;
|
||||
_compute: null | ((p?: T) => T);
|
||||
_name: string | undefined;
|
||||
_equals: false | ((a: T, b: T) => boolean);
|
||||
_unobserved: (() => void) | undefined;
|
||||
_pureWrite: boolean;
|
||||
/** Whether the computation is an error or has ancestors that are unresolved */
|
||||
_stateFlags: number;
|
||||
/** Which flags raised by sources are handled, vs. being passed through. */
|
||||
_handlerMask: number;
|
||||
_time: number;
|
||||
_forceNotify: boolean;
|
||||
constructor(initialValue: T | undefined, compute: null | ((p?: T) => T), options?: SignalOptions<T>);
|
||||
_read(): T;
|
||||
/**
|
||||
* Return the current value of this computation
|
||||
* Automatically re-executes the surrounding computation when the value changes
|
||||
*/
|
||||
read(): T;
|
||||
/**
|
||||
* Return the current value of this computation
|
||||
* Automatically re-executes the surrounding computation when the value changes
|
||||
*
|
||||
* If the computation has any unresolved ancestors, this function waits for the value to resolve
|
||||
* before continuing
|
||||
*/
|
||||
wait(): T;
|
||||
/** Update the computation with a new value. */
|
||||
write(value: T | ((currentValue: T) => T) | UNCHANGED, flags?: number, raw?: boolean): T;
|
||||
/**
|
||||
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
||||
*/
|
||||
_notify(state: number, skipQueue?: boolean): void;
|
||||
/**
|
||||
* Notify the computation that one of its sources has changed flags.
|
||||
*
|
||||
* @param mask A bitmask for which flag(s) were changed.
|
||||
* @param newFlags The source's new flags, masked to just the changed ones.
|
||||
*/
|
||||
_notifyFlags(mask: Flags, newFlags: Flags): void;
|
||||
_setError(error: unknown): void;
|
||||
/**
|
||||
* This is the core part of the reactivity system, which makes sure that the values are updated
|
||||
* before they are read. We've also adapted it to return the loading state of the computation,
|
||||
* so that we can propagate that to the computation's observers.
|
||||
*
|
||||
* This function will ensure that the value and states we read from the computation are up to date
|
||||
*/
|
||||
_updateIfNecessary(): void;
|
||||
/**
|
||||
* Remove ourselves from the owner graph and the computation graph
|
||||
*/
|
||||
_disposeNode(): void;
|
||||
}
|
||||
/**
|
||||
* Reruns a computation's _compute function, producing a new value and keeping track of dependencies.
|
||||
*
|
||||
* It handles the updating of sources and observers, disposal of previous executions,
|
||||
* and error handling if the _compute function throws. It also sets the node as loading
|
||||
* if it reads any parents that are currently loading.
|
||||
*/
|
||||
export declare function update<T>(node: Computation<T>): void;
|
||||
export declare function isEqual<T>(a: T, b: T): boolean;
|
||||
/**
|
||||
* Returns the current value stored inside the given compute function without triggering any
|
||||
* dependencies. Use `untrack` if you want to also disable owner tracking.
|
||||
*/
|
||||
export declare function untrack<T>(fn: () => T): T;
|
||||
/**
|
||||
* Returns true if the given functinon contains signals that have been updated since the last time
|
||||
* the parent computation was run.
|
||||
*/
|
||||
export declare function hasUpdated(fn: () => any): boolean;
|
||||
/**
|
||||
* Returns an accessor that is true if the given function contains async signals that are out of date.
|
||||
*/
|
||||
export declare function isPending(fn: () => any): boolean;
|
||||
export declare function isPending(fn: () => any, loadingValue: boolean): boolean;
|
||||
/**
|
||||
* Attempts to resolve value of expression synchronously returning the last resolved value for any async computation.
|
||||
*/
|
||||
export declare function latest<T>(fn: () => T): T;
|
||||
export declare function latest<T, U>(fn: () => T, fallback: U): T | U;
|
||||
/**
|
||||
* Runs the given function in the given observer.
|
||||
*
|
||||
* Warning: Usually there are simpler ways of modeling a problem that avoid using this function
|
||||
*/
|
||||
export declare function runWithObserver<T>(observer: Computation, run: () => T): T | undefined;
|
||||
/**
|
||||
* A convenient wrapper that calls `compute` with the `owner` and `observer` and is guaranteed
|
||||
* to reset the global context after the computation is finished even if an error is thrown.
|
||||
*/
|
||||
export declare function compute<T>(owner: Owner | null, fn: (val: T) => T, observer: Computation<T>): T;
|
||||
export declare function compute<T>(owner: Owner | null, fn: (val: undefined) => T, observer: null): T;
|
||||
export {};
|
||||
@@ -1,37 +0,0 @@
|
||||
import { EFFECT_RENDER, EFFECT_USER } from "./constants.js";
|
||||
import { Computation, type SignalOptions } from "./core.js";
|
||||
/**
|
||||
* Effects are the leaf nodes of our reactive graph. When their sources change, they are
|
||||
* automatically added to the queue of effects to re-execute, which will cause them to fetch their
|
||||
* sources and recompute
|
||||
*/
|
||||
export declare class Effect<T = any> extends Computation<T> {
|
||||
_effect: (val: T, prev: T | undefined) => void | (() => void);
|
||||
_onerror: ((err: unknown, cleanup: () => void) => void) | undefined;
|
||||
_cleanup: (() => void) | undefined;
|
||||
_modified: boolean;
|
||||
_prevValue: T | undefined;
|
||||
_type: typeof EFFECT_RENDER | typeof EFFECT_USER;
|
||||
constructor(initialValue: T, compute: (val?: T) => T, effect: (val: T, prev: T | undefined) => void | (() => void), error?: (err: unknown) => void | (() => void), options?: SignalOptions<T> & {
|
||||
render?: boolean;
|
||||
defer?: boolean;
|
||||
});
|
||||
write(value: T, flags?: number): T;
|
||||
_notify(state: number, skipQueue?: boolean): void;
|
||||
_setError(error: unknown): void;
|
||||
_disposeNode(): void;
|
||||
_run(type: number): void;
|
||||
}
|
||||
export declare class EagerComputation<T = any> extends Computation<T> {
|
||||
constructor(initialValue: T, compute: () => T, options?: SignalOptions<T> & {
|
||||
defer?: boolean;
|
||||
});
|
||||
_notify(state: number, skipQueue?: boolean): void;
|
||||
_run(): void;
|
||||
}
|
||||
export declare class FirewallComputation extends Computation {
|
||||
firewall: boolean;
|
||||
constructor(compute: () => void);
|
||||
_notify(state: number, skipQueue?: boolean): void;
|
||||
_run(): void;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
export declare class NotReadyError extends Error {
|
||||
}
|
||||
export declare class NoOwnerError extends Error {
|
||||
constructor();
|
||||
}
|
||||
export declare class ContextNotFoundError extends Error {
|
||||
constructor();
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
export type Flags = number;
|
||||
export declare const ERROR_OFFSET = 0;
|
||||
export declare const ERROR_BIT: number;
|
||||
export declare const ERROR: unique symbol;
|
||||
export declare const LOADING_OFFSET = 1;
|
||||
export declare const LOADING_BIT: number;
|
||||
export declare const LOADING: unique symbol;
|
||||
export declare const UNINITIALIZED_OFFSET = 2;
|
||||
export declare const UNINITIALIZED_BIT: number;
|
||||
export declare const UNINITIALIZED: unique symbol;
|
||||
export declare const DEFAULT_FLAGS: number;
|
||||
@@ -1,7 +0,0 @@
|
||||
export { ContextNotFoundError, NoOwnerError, NotReadyError } from "./error.js";
|
||||
export { Owner, createContext, getContext, setContext, hasContext, getOwner, onCleanup, type Context, type ContextRecord, type Disposable } from "./owner.js";
|
||||
export { Computation, getObserver, isEqual, untrack, hasUpdated, isPending, latest, UNCHANGED, compute, runWithObserver, type SignalOptions } from "./core.js";
|
||||
export { Effect, EagerComputation } from "./effect.js";
|
||||
export { flush, Queue, incrementClock, getClock, type IQueue } from "./scheduler.js";
|
||||
export * from "./constants.js";
|
||||
export * from "./flags.js";
|
||||
@@ -1,95 +0,0 @@
|
||||
/**
|
||||
* Owner tracking is used to enable nested tracking scopes with automatic cleanup.
|
||||
* We also use owners to also keep track of which error handling context we are in.
|
||||
*
|
||||
* If you write the following
|
||||
*
|
||||
* const a = createOwner(() => {
|
||||
* const b = createOwner(() => {});
|
||||
*
|
||||
* const c = createOwner(() => {
|
||||
* const d = createOwner(() => {});
|
||||
* });
|
||||
*
|
||||
* const e = createOwner(() => {});
|
||||
* });
|
||||
*
|
||||
* The owner tree will look like this:
|
||||
*
|
||||
* a
|
||||
* /|\
|
||||
* b-c-e
|
||||
* |
|
||||
* d
|
||||
*
|
||||
* Following the _nextSibling pointers of each owner will first give you its children, and then its siblings (in reverse).
|
||||
* a -> e -> c -> d -> b
|
||||
*
|
||||
* Note that the owner tree is largely orthogonal to the reactivity tree, and is much closer to the component tree.
|
||||
*/
|
||||
import { type IQueue } from "./scheduler.js";
|
||||
export type ContextRecord = Record<string | symbol, unknown>;
|
||||
export interface Disposable {
|
||||
(): void;
|
||||
}
|
||||
/**
|
||||
* Returns the currently executing parent owner.
|
||||
*/
|
||||
export declare function getOwner(): Owner | null;
|
||||
export declare function setOwner(owner: Owner | null): Owner | null;
|
||||
export declare class Owner {
|
||||
_parent: Owner | null;
|
||||
_nextSibling: Owner | null;
|
||||
_prevSibling: Owner | null;
|
||||
_state: number;
|
||||
_disposal: Disposable | Disposable[] | null;
|
||||
_context: ContextRecord;
|
||||
_queue: IQueue;
|
||||
_childCount: number;
|
||||
id: string | null;
|
||||
constructor(id?: string | null, skipAppend?: boolean);
|
||||
append(child: Owner): void;
|
||||
dispose(this: Owner, self?: boolean): void;
|
||||
_disposeNode(): void;
|
||||
emptyDisposal(): void;
|
||||
getNextChildId(): string;
|
||||
}
|
||||
export interface Context<T> {
|
||||
readonly id: symbol;
|
||||
readonly defaultValue: T | undefined;
|
||||
}
|
||||
/**
|
||||
* Context provides a form of dependency injection. It is used to save from needing to pass
|
||||
* data as props through intermediate components. This function creates a new context object
|
||||
* that can be used with `getContext` and `setContext`.
|
||||
*
|
||||
* A default value can be provided here which will be used when a specific value is not provided
|
||||
* via a `setContext` call.
|
||||
*/
|
||||
export declare function createContext<T>(defaultValue?: T, description?: string): Context<T>;
|
||||
/**
|
||||
* Attempts to get a context value for the given key.
|
||||
*
|
||||
* @throws `NoOwnerError` if there's no owner at the time of call.
|
||||
* @throws `ContextNotFoundError` if a context value has not been set yet.
|
||||
*/
|
||||
export declare function getContext<T>(context: Context<T>, owner?: Owner | null): T;
|
||||
/**
|
||||
* Attempts to set a context value on the parent scope with the given key.
|
||||
*
|
||||
* @throws `NoOwnerError` if there's no owner at the time of call.
|
||||
*/
|
||||
export declare function setContext<T>(context: Context<T>, value?: T, owner?: Owner | null): void;
|
||||
/**
|
||||
* Whether the given context is currently defined.
|
||||
*/
|
||||
export declare function hasContext(context: Context<any>, owner?: Owner | null): boolean;
|
||||
/**
|
||||
* Runs an effect once before the reactive scope is disposed
|
||||
* @param fn an effect that should run only once on cleanup
|
||||
*
|
||||
* @returns the same {@link fn} function that was passed in
|
||||
*
|
||||
* @description https://docs.solidjs.com/reference/lifecycle/on-cleanup
|
||||
*/
|
||||
export declare function onCleanup(fn: Disposable): Disposable;
|
||||
@@ -1,33 +0,0 @@
|
||||
export declare function getClock(): number;
|
||||
export declare function incrementClock(): void;
|
||||
type QueueCallback = (type: number) => void;
|
||||
export interface IQueue {
|
||||
enqueue(type: number, fn: QueueCallback): void;
|
||||
run(type: number): boolean | void;
|
||||
flush(): void;
|
||||
addChild(child: IQueue): void;
|
||||
removeChild(child: IQueue): void;
|
||||
created: number;
|
||||
notify(...args: any[]): boolean;
|
||||
_parent: IQueue | null;
|
||||
}
|
||||
export declare class Queue implements IQueue {
|
||||
_parent: IQueue | null;
|
||||
_running: boolean;
|
||||
_queues: [QueueCallback[], QueueCallback[]];
|
||||
_children: IQueue[];
|
||||
created: number;
|
||||
enqueue(type: number, fn: QueueCallback): void;
|
||||
run(type: number): void;
|
||||
flush(): void;
|
||||
addChild(child: IQueue): void;
|
||||
removeChild(child: IQueue): void;
|
||||
notify(...args: any[]): boolean;
|
||||
}
|
||||
export declare const globalQueue: Queue;
|
||||
/**
|
||||
* By default, changes are batched on the microtask queue which is an async process. You can flush
|
||||
* the queue synchronously to get the latest updates by calling `flush()`.
|
||||
*/
|
||||
export declare function flush(): void;
|
||||
export {};
|
||||
@@ -1,6 +0,0 @@
|
||||
export { Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, createContext, flush, getContext, setContext, hasContext, getOwner, onCleanup, getObserver, isEqual, untrack, hasUpdated, isPending, latest, runWithObserver, SUPPORTS_PROXY } from "./core/index.js";
|
||||
export type { SignalOptions, Context, ContextRecord, Disposable, IQueue } from "./core/index.js";
|
||||
export { mapArray, repeat, type Maybe } from "./map.js";
|
||||
export * from "./signals.js";
|
||||
export * from "./store/index.js";
|
||||
export { createSuspense, createErrorBoundary, createBoundary, flatten, type BoundaryMode } from "./boundaries.js";
|
||||
@@ -1,22 +0,0 @@
|
||||
import type { Accessor } from "./signals.js";
|
||||
export type Maybe<T> = T | void | null | undefined | false;
|
||||
/**
|
||||
* Reactively transforms an array with a callback function - underlying helper for the `<For>` control flow
|
||||
*
|
||||
* similar to `Array.prototype.map`, but gets the value and index as accessors, transforms only values that changed and returns an accessor and reactively tracks changes to the list.
|
||||
*
|
||||
* @description https://docs.solidjs.com/reference/reactive-utilities/map-array
|
||||
*/
|
||||
export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: Accessor<number>) => MappedItem, options?: {
|
||||
keyed?: boolean | ((item: Item) => any);
|
||||
fallback?: Accessor<any>;
|
||||
}): Accessor<MappedItem[]>;
|
||||
/**
|
||||
* Reactively repeats a callback function the count provided - underlying helper for the `<Repeat>` control flow
|
||||
*
|
||||
* @description https://docs.solidjs.com/reference/reactive-utilities/repeat
|
||||
*/
|
||||
export declare function repeat(count: Accessor<number>, map: (index: number) => any, options?: {
|
||||
from?: Accessor<number | undefined>;
|
||||
fallback?: Accessor<any>;
|
||||
}): Accessor<any[]>;
|
||||
@@ -1,182 +0,0 @@
|
||||
import type { SignalOptions } from "./core/index.js";
|
||||
import { Owner } from "./core/index.js";
|
||||
export type Accessor<T> = () => T;
|
||||
export type Setter<in out T> = {
|
||||
<U extends T>(...args: undefined extends T ? [] : [value: Exclude<U, Function> | ((prev: T) => U)]): undefined extends T ? undefined : U;
|
||||
<U extends T>(value: (prev: T) => U): U;
|
||||
<U extends T>(value: Exclude<U, Function>): U;
|
||||
<U extends T>(value: Exclude<U, Function> | ((prev: T) => U)): U;
|
||||
};
|
||||
export type Signal<T> = [get: Accessor<T>, set: Setter<T>];
|
||||
export type ComputeFunction<Prev, Next extends Prev = Prev> = (v: Prev) => Next;
|
||||
export type EffectFunction<Prev, Next extends Prev = Prev> = (v: Next, p?: Prev) => (() => void) | void;
|
||||
export type EffectBundle<Prev, Next extends Prev = Prev> = {
|
||||
effect: EffectFunction<Prev, Next>;
|
||||
error: (err: unknown, cleanup: () => void) => void;
|
||||
};
|
||||
export interface EffectOptions {
|
||||
name?: string;
|
||||
defer?: boolean;
|
||||
}
|
||||
export interface MemoOptions<T> {
|
||||
name?: string;
|
||||
equals?: false | ((prev: T, next: T) => boolean);
|
||||
}
|
||||
export type NoInfer<T extends any> = [T][T extends any ? 0 : never];
|
||||
/**
|
||||
* Creates a simple reactive state with a getter and setter
|
||||
* ```typescript
|
||||
* const [state: Accessor<T>, setState: Setter<T>] = createSignal<T>(
|
||||
* value: T,
|
||||
* options?: { name?: string, equals?: false | ((prev: T, next: T) => boolean) }
|
||||
* )
|
||||
* ```
|
||||
* @param value initial value of the state; if empty, the state's type will automatically extended with undefined; otherwise you need to extend the type manually if you want setting to undefined not be an error
|
||||
* @param options optional object with a name for debugging purposes and equals, a comparator function for the previous and next value to allow fine-grained control over the reactivity
|
||||
*
|
||||
* @returns ```typescript
|
||||
* [state: Accessor<T>, setState: Setter<T>]
|
||||
* ```
|
||||
* * the Accessor is a function that returns the current value and registers each call to the reactive root
|
||||
* * the Setter is a function that allows directly setting or mutating the value:
|
||||
* ```typescript
|
||||
* const [count, setCount] = createSignal(0);
|
||||
* setCount(count => count + 1);
|
||||
* ```
|
||||
*
|
||||
* @description https://docs.solidjs.com/reference/basic-reactivity/create-signal
|
||||
*/
|
||||
export declare function createSignal<T>(): Signal<T | undefined>;
|
||||
export declare function createSignal<T>(value: Exclude<T, Function>, options?: SignalOptions<T>): Signal<T>;
|
||||
export declare function createSignal<T>(fn: ComputeFunction<T>, initialValue?: T, options?: SignalOptions<T>): Signal<T>;
|
||||
/**
|
||||
* Creates a readonly derived reactive memoized signal
|
||||
* ```typescript
|
||||
* export function createMemo<T>(
|
||||
* compute: (v: T) => T,
|
||||
* value?: T,
|
||||
* options?: { name?: string, equals?: false | ((prev: T, next: T) => boolean) }
|
||||
* ): () => T;
|
||||
* ```
|
||||
* @param compute a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
|
||||
* @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
|
||||
* @param options allows to set a name in dev mode for debugging purposes and use a custom comparison function in equals
|
||||
*
|
||||
* @description https://docs.solidjs.com/reference/basic-reactivity/create-memo
|
||||
*/
|
||||
export declare function createMemo<Next extends Prev, Prev = Next>(compute: ComputeFunction<undefined | NoInfer<Prev>, Next>): Accessor<Next>;
|
||||
export declare function createMemo<Next extends Prev, Init = Next, Prev = Next>(compute: ComputeFunction<Init | Prev, Next>, value: Init, options?: MemoOptions<Next>): Accessor<Next>;
|
||||
/**
|
||||
* Creates a readonly derived async reactive memoized signal
|
||||
* ```typescript
|
||||
* export function createAsync<T>(
|
||||
* compute: (v: T) => Promise<T> | T,
|
||||
* value?: T,
|
||||
* options?: { name?: string, equals?: false | ((prev: T, next: T) => boolean) }
|
||||
* ): () => T;
|
||||
* ```
|
||||
* @param compute a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
|
||||
* @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
|
||||
* @param options allows to set a name in dev mode for debugging purposes and use a custom comparison function in equals
|
||||
*
|
||||
* @description https://docs.solidjs.com/reference/basic-reactivity/create-async
|
||||
*/
|
||||
export declare function createAsync<T>(compute: (prev: T | undefined, refreshing: boolean) => Promise<T> | AsyncIterable<T> | T, value?: T, options?: MemoOptions<T>): Accessor<T> & {
|
||||
refresh: () => void;
|
||||
};
|
||||
/**
|
||||
* Creates a reactive effect that runs after the render phase
|
||||
* ```typescript
|
||||
* export function createEffect<T>(
|
||||
* compute: (prev: T) => T,
|
||||
* effect: (v: T, prev: T) => (() => void) | void,
|
||||
* value?: T,
|
||||
* options?: { name?: string }
|
||||
* ): void;
|
||||
* ```
|
||||
* @param compute a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
|
||||
* @param effect a function that receives the new value and is used to perform side effects, return a cleanup function to run on disposal
|
||||
* @param error an optional function that receives an error if thrown during the computation
|
||||
* @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
|
||||
* @param options allows to set a name in dev mode for debugging purposes
|
||||
*
|
||||
* @description https://docs.solidjs.com/reference/basic-reactivity/create-effect
|
||||
*/
|
||||
export declare function createEffect<Next>(compute: ComputeFunction<undefined | NoInfer<Next>, Next>, effect: EffectFunction<NoInfer<Next>, Next> | EffectBundle<NoInfer<Next>, Next>): void;
|
||||
export declare function createEffect<Next, Init = Next>(compute: ComputeFunction<Init | Next, Next>, effect: EffectFunction<Next, Next> | EffectBundle<Next, Next>, value: Init, options?: EffectOptions): void;
|
||||
/**
|
||||
* Creates a reactive computation that runs during the render phase as DOM elements are created and updated but not necessarily connected
|
||||
* ```typescript
|
||||
* export function createRenderEffect<T>(
|
||||
* compute: (prev: T) => T,
|
||||
* effect: (v: T, prev: T) => (() => void) | void,
|
||||
* value?: T,
|
||||
* options?: { name?: string }
|
||||
* ): void;
|
||||
* ```
|
||||
* @param compute a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
|
||||
* @param effect a function that receives the new value and is used to perform side effects
|
||||
* @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
|
||||
* @param options allows to set a name in dev mode for debugging purposes
|
||||
*
|
||||
* @description https://docs.solidjs.com/reference/secondary-primitives/create-render-effect
|
||||
*/
|
||||
export declare function createRenderEffect<Next>(compute: ComputeFunction<undefined | NoInfer<Next>, Next>, effect: EffectFunction<NoInfer<Next>, Next>): void;
|
||||
export declare function createRenderEffect<Next, Init = Next>(compute: ComputeFunction<Init | Next, Next>, effect: EffectFunction<Next, Next>, value: Init, options?: EffectOptions): void;
|
||||
/**
|
||||
* Creates a new non-tracked reactive context with manual disposal
|
||||
*
|
||||
* @param fn a function in which the reactive state is scoped
|
||||
* @returns the output of `fn`.
|
||||
*
|
||||
* @description https://docs.solidjs.com/reference/reactive-utilities/create-root
|
||||
*/
|
||||
export declare function createRoot<T>(init: ((dispose: () => void) => T) | (() => T), options?: {
|
||||
id: string;
|
||||
}): T;
|
||||
/**
|
||||
* Runs the given function in the given owner to move ownership of nested primitives and cleanups.
|
||||
* This method untracks the current scope.
|
||||
*
|
||||
* Warning: Usually there are simpler ways of modeling a problem that avoid using this function
|
||||
*/
|
||||
export declare function runWithOwner<T>(owner: Owner | null, run: () => T): T;
|
||||
/**
|
||||
* Returns a promise of the resolved value of a reactive expression
|
||||
* @param fn a reactive expression to resolve
|
||||
*/
|
||||
export declare function resolve<T>(fn: () => T): Promise<T>;
|
||||
/**
|
||||
* Runs the given function and returns a tuple with the result or an error.
|
||||
* If the function throws an error, it will be caught and returned as the first element of the tuple.
|
||||
* If the function returns a promise, it will resolve to a tuple with the result or an error.
|
||||
*
|
||||
* @param fn The function to run.
|
||||
* @returns A tuple with either [undefined, result] or [error].
|
||||
*
|
||||
* @description https://docs.solidjs.com/reference/reactive-utilities/try-catch
|
||||
*/
|
||||
export type TryCatchResult<T, E> = [undefined, T] | [E];
|
||||
export declare function tryCatch<T, E = Error>(fn: () => Promise<T>): Promise<TryCatchResult<T, E>>;
|
||||
export declare function tryCatch<T, E = Error>(fn: () => T): TryCatchResult<T, E>;
|
||||
/**
|
||||
* Runs the given function in a transition scope, allowing for batch updates and optimizations.
|
||||
* This is useful for grouping multiple state updates together to avoid unnecessary re-renders.
|
||||
*
|
||||
* @param fn A function that receives a resume function to continue the transition.
|
||||
* The resume function can be called with another function to continue the transition.
|
||||
*
|
||||
* @description https://docs.solidjs.com/reference/advanced-reactivity/transition
|
||||
*/
|
||||
export declare function transition(fn: (resume: (fn: () => any | Promise<any>) => void) => any | Promise<any>): void;
|
||||
/**
|
||||
* Creates an optimistic signal that can be used to optimistically update a value
|
||||
* and then revert it back to the previous value at end of transition.
|
||||
*
|
||||
* @param initial The initial value of the signal.
|
||||
* @param compute An optional function to compute the next value based on the previous value and change.
|
||||
* @param options Optional signal options.
|
||||
*
|
||||
* @returns A tuple containing an accessor for the current value and a setter function to apply changes.
|
||||
*/
|
||||
export declare function createOptimistic<T, U>(initial: T, compute?: (prev: T, change: U) => void, options?: SignalOptions<T>): [Accessor<T>, (v: U) => void];
|
||||
@@ -1,6 +0,0 @@
|
||||
export type { Store, StoreSetter, StoreNode, NotWrappable, SolidStore } from "./store.js";
|
||||
export type { Merge, Omit } from "./utils.js";
|
||||
export { isWrappable, createStore, deep, $TRACK, $PROXY, $TARGET } from "./store.js";
|
||||
export { createProjection } from "./projection.js";
|
||||
export { reconcile } from "./reconcile.js";
|
||||
export { snapshot, merge, omit } from "./utils.js";
|
||||
@@ -1,7 +0,0 @@
|
||||
import { type Store } from "./store.js";
|
||||
/**
|
||||
* Creates a mutable derived value
|
||||
*
|
||||
* @see {@link https://github.com/solidjs/x-reactivity#createprojection}
|
||||
*/
|
||||
export declare function createProjection<T extends Object>(fn: (draft: T) => void, initialValue?: T): Store<T>;
|
||||
@@ -1 +0,0 @@
|
||||
export declare function reconcile<T extends U, U>(value: T, key: string | ((item: NonNullable<any>) => any), all?: boolean): (state: U) => void;
|
||||
@@ -1,33 +0,0 @@
|
||||
import { Computation } from "../core/index.js";
|
||||
export type Store<T> = Readonly<T>;
|
||||
export type StoreSetter<T> = (fn: (state: T) => void) => void;
|
||||
type DataNode = Computation<any>;
|
||||
type DataNodes = Record<PropertyKey, DataNode>;
|
||||
export declare const $TRACK: unique symbol, $DEEP: unique symbol, $TARGET: unique symbol, $PROXY: unique symbol, $DELETED: unique symbol;
|
||||
export declare const STORE_VALUE = "v", STORE_OVERRIDE = "o", STORE_NODE = "n", STORE_HAS = "h", STORE_WRAP = "w", STORE_LOOKUP = "l";
|
||||
export type StoreNode = {
|
||||
[$PROXY]: any;
|
||||
[STORE_VALUE]: Record<PropertyKey, any>;
|
||||
[STORE_OVERRIDE]?: Record<PropertyKey, any>;
|
||||
[STORE_NODE]?: DataNodes;
|
||||
[STORE_HAS]?: DataNodes;
|
||||
[STORE_WRAP]?: (value: any, target?: StoreNode) => any;
|
||||
[STORE_LOOKUP]?: WeakMap<any, any>;
|
||||
};
|
||||
export declare namespace SolidStore {
|
||||
interface Unwrappable {
|
||||
}
|
||||
}
|
||||
export type NotWrappable = string | number | bigint | symbol | boolean | Function | null | undefined | SolidStore.Unwrappable[keyof SolidStore.Unwrappable];
|
||||
export declare function createStoreProxy<T extends object>(value: T, traps?: ProxyHandler<StoreNode>, extend?: Record<PropertyKey, any>): any;
|
||||
export declare const storeLookup: WeakMap<object, any>;
|
||||
export declare function wrap<T extends Record<PropertyKey, any>>(value: T, target?: StoreNode): T;
|
||||
export declare function isWrappable<T>(obj: T | NotWrappable): obj is T;
|
||||
export declare function getKeys(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, enumerable?: boolean): PropertyKey[];
|
||||
export declare function getPropertyDescriptor(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, property: PropertyKey): PropertyDescriptor | undefined;
|
||||
export declare const storeTraps: ProxyHandler<StoreNode>;
|
||||
export declare function storeSetter<T extends object>(store: Store<T>, fn: (draft: T) => void): void;
|
||||
export declare function createStore<T extends object = {}>(store: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
|
||||
export declare function createStore<T extends object = {}>(fn: (store: T) => void, store: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
|
||||
export declare function deep<T extends object>(store: Store<T>): Store<any>;
|
||||
export {};
|
||||
@@ -1,36 +0,0 @@
|
||||
/**
|
||||
* Returns a non reactive copy of the store object.
|
||||
* It will attempt to preserver the original reference unless the value has been modified.
|
||||
* @param item store proxy object
|
||||
*/
|
||||
export declare function snapshot<T>(item: T): T;
|
||||
export declare function snapshot<T>(item: T, map?: Map<unknown, unknown>, lookup?: WeakMap<any, any>): T;
|
||||
type DistributeOverride<T, F> = T extends undefined ? F : T;
|
||||
type Override<T, U> = T extends any ? U extends any ? {
|
||||
[K in keyof T]: K extends keyof U ? DistributeOverride<U[K], T[K]> : T[K];
|
||||
} & {
|
||||
[K in keyof U]: K extends keyof T ? DistributeOverride<U[K], T[K]> : U[K];
|
||||
} : T & U : T & U;
|
||||
type OverrideSpread<T, U> = T extends any ? {
|
||||
[K in keyof ({
|
||||
[K in keyof T]: any;
|
||||
} & {
|
||||
[K in keyof U]?: any;
|
||||
} & {
|
||||
[K in U extends any ? keyof U : keyof U]?: any;
|
||||
})]: K extends keyof T ? Exclude<U extends any ? U[K & keyof U] : never, undefined> | T[K] : U extends any ? U[K & keyof U] : never;
|
||||
} : T & U;
|
||||
type Simplify<T> = T extends any ? {
|
||||
[K in keyof T]: T[K];
|
||||
} : T;
|
||||
type _Merge<T extends unknown[], Curr = {}> = T extends [
|
||||
infer Next | (() => infer Next),
|
||||
...infer Rest
|
||||
] ? _Merge<Rest, Override<Curr, Next>> : T extends [...infer Rest, infer Next | (() => infer Next)] ? Override<_Merge<Rest, Curr>, Next> : T extends [] ? Curr : T extends (infer I | (() => infer I))[] ? OverrideSpread<Curr, I> : Curr;
|
||||
export type Merge<T extends unknown[]> = Simplify<_Merge<T>>;
|
||||
export declare function merge<T extends unknown[]>(...sources: T): Merge<T>;
|
||||
export type Omit<T, K extends readonly (keyof T)[]> = {
|
||||
[P in keyof T as Exclude<P, K[number]>]: T[P];
|
||||
};
|
||||
export declare function omit<T extends Record<any, any>, K extends readonly (keyof T)[]>(props: T, ...keys: K): Omit<T, K>;
|
||||
export {};
|
||||
@@ -16,8 +16,6 @@
|
||||
* @typedef {Accessor<T> & { set: Setter<T>; reset: VoidFunction }} Signal
|
||||
*/
|
||||
|
||||
console.log("bob");
|
||||
|
||||
import {
|
||||
createSignal,
|
||||
createEffect,
|
||||
|
||||
Reference in New Issue
Block a user