@manyducks.co/dolla 0.75.1 → 0.77.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +82 -95
- package/lib/index.js.map +3 -3
- package/lib/stores/router.d.ts +5 -1
- package/notes/views.md +174 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -502,96 +502,80 @@ function computed(...args) {
|
|
|
502
502
|
throw new Error(`Must pass at least one value before the callback function.`);
|
|
503
503
|
}
|
|
504
504
|
const readables = args;
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
if (isReadable(computedValue)) {
|
|
521
|
-
lastComputedValue = computedValue;
|
|
522
|
-
return computedValue[OBSERVE]((current) => {
|
|
523
|
-
callback(current);
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
if (!deepEqual(computedValue, lastComputedValue)) {
|
|
527
|
-
callback(computedValue);
|
|
528
|
-
lastComputedValue = computedValue;
|
|
529
|
-
}
|
|
530
|
-
});
|
|
531
|
-
}
|
|
532
|
-
};
|
|
533
|
-
} else {
|
|
534
|
-
let updateValue2 = function() {
|
|
535
|
-
const computedValue = compute(...observedValues);
|
|
536
|
-
if (!deepEqual(computedValue, latestComputedValue)) {
|
|
537
|
-
latestComputedValue = computedValue;
|
|
538
|
-
for (const callback of observers) {
|
|
539
|
-
callback(computedValue);
|
|
540
|
-
}
|
|
505
|
+
const observers = [];
|
|
506
|
+
let stopCallbacks = [];
|
|
507
|
+
let isObserving = false;
|
|
508
|
+
let observedValues = [];
|
|
509
|
+
let valuesChanged = [];
|
|
510
|
+
let latestComputedValue = UNOBSERVED;
|
|
511
|
+
function updateValue() {
|
|
512
|
+
if (!valuesChanged.some((x) => x)) {
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
const computedValue = compute(...observedValues);
|
|
516
|
+
if (!deepEqual(computedValue, latestComputedValue)) {
|
|
517
|
+
latestComputedValue = computedValue;
|
|
518
|
+
for (const callback of observers) {
|
|
519
|
+
callback(computedValue);
|
|
541
520
|
}
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
521
|
+
}
|
|
522
|
+
for (let i = 0; i < observedValues.length; i++) {
|
|
523
|
+
valuesChanged[i] = false;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
function startObserving() {
|
|
527
|
+
if (isObserving)
|
|
528
|
+
return;
|
|
529
|
+
for (let i = 0; i < readables.length; i++) {
|
|
530
|
+
const readable2 = readables[i];
|
|
531
|
+
stopCallbacks.push(
|
|
532
|
+
observe(readable2, (value) => {
|
|
533
|
+
if (!deepEqual(observedValues[i], value)) {
|
|
549
534
|
observedValues[i] = value;
|
|
535
|
+
valuesChanged[i] = true;
|
|
550
536
|
if (isObserving) {
|
|
551
|
-
|
|
537
|
+
updateValue();
|
|
552
538
|
}
|
|
553
|
-
}
|
|
554
|
-
)
|
|
539
|
+
}
|
|
540
|
+
})
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
observedValues = readables.map((x) => x.get());
|
|
544
|
+
for (let i = 0; i < observedValues.length; i++) {
|
|
545
|
+
valuesChanged[i] = true;
|
|
546
|
+
}
|
|
547
|
+
isObserving = true;
|
|
548
|
+
updateValue();
|
|
549
|
+
}
|
|
550
|
+
function stopObserving() {
|
|
551
|
+
isObserving = false;
|
|
552
|
+
for (const callback of stopCallbacks) {
|
|
553
|
+
callback();
|
|
554
|
+
}
|
|
555
|
+
stopCallbacks = [];
|
|
556
|
+
}
|
|
557
|
+
return {
|
|
558
|
+
get: () => {
|
|
559
|
+
if (isObserving) {
|
|
560
|
+
return latestComputedValue;
|
|
561
|
+
} else {
|
|
562
|
+
return compute(...readables.map((x) => x.get()));
|
|
555
563
|
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
isObserving = false;
|
|
561
|
-
for (const callback of stopCallbacks) {
|
|
562
|
-
callback();
|
|
564
|
+
},
|
|
565
|
+
[OBSERVE]: (callback) => {
|
|
566
|
+
if (!isObserving) {
|
|
567
|
+
startObserving();
|
|
563
568
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
let observedValues = [];
|
|
571
|
-
let latestComputedValue = UNOBSERVED;
|
|
572
|
-
return {
|
|
573
|
-
get: () => {
|
|
574
|
-
if (isObserving) {
|
|
575
|
-
return latestComputedValue;
|
|
576
|
-
} else {
|
|
577
|
-
return compute(...readables.map((x) => x.get()));
|
|
569
|
+
callback(latestComputedValue);
|
|
570
|
+
observers.push(callback);
|
|
571
|
+
return function stop() {
|
|
572
|
+
observers.splice(observers.indexOf(callback), 1);
|
|
573
|
+
if (observers.length === 0) {
|
|
574
|
+
stopObserving();
|
|
578
575
|
}
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
startObserving2();
|
|
583
|
-
}
|
|
584
|
-
callback(latestComputedValue);
|
|
585
|
-
observers.push(callback);
|
|
586
|
-
return function stop() {
|
|
587
|
-
observers.splice(observers.indexOf(callback), 1);
|
|
588
|
-
if (observers.length === 0) {
|
|
589
|
-
stopObserving2();
|
|
590
|
-
}
|
|
591
|
-
};
|
|
592
|
-
}
|
|
593
|
-
};
|
|
594
|
-
}
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
};
|
|
595
579
|
}
|
|
596
580
|
function writable(value) {
|
|
597
581
|
if (isWritable(value)) {
|
|
@@ -2995,6 +2979,9 @@ function resolvePath(base, part) {
|
|
|
2995
2979
|
function parseQueryParams(query) {
|
|
2996
2980
|
if (!query)
|
|
2997
2981
|
return {};
|
|
2982
|
+
if (query.startsWith("?")) {
|
|
2983
|
+
query = query.slice(1);
|
|
2984
|
+
}
|
|
2998
2985
|
const entries = query.split("&").filter((x) => x.trim() !== "").map((entry) => {
|
|
2999
2986
|
const [key, value] = entry.split("=").map((x) => x.trim());
|
|
3000
2987
|
if (value.toLowerCase() === "true") {
|
|
@@ -3252,21 +3239,19 @@ function RouterStore(ctx) {
|
|
|
3252
3239
|
const $$pattern = $$(null);
|
|
3253
3240
|
const $$path = $$("");
|
|
3254
3241
|
const $$params = $$({});
|
|
3255
|
-
const $$query = $$(
|
|
3256
|
-
let isRouteChange = true;
|
|
3242
|
+
const $$query = $$(parseQueryParams(window.location.search));
|
|
3257
3243
|
ctx.observe($$query, (current) => {
|
|
3258
|
-
if (isRouteChange) {
|
|
3259
|
-
isRouteChange = false;
|
|
3260
|
-
return;
|
|
3261
|
-
}
|
|
3262
3244
|
const params = new URLSearchParams();
|
|
3263
3245
|
for (const key in current) {
|
|
3264
3246
|
params.set(key, String(current[key]));
|
|
3265
3247
|
}
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3248
|
+
const search = "?" + params.toString();
|
|
3249
|
+
if (search != history.location.search) {
|
|
3250
|
+
history.replace({
|
|
3251
|
+
pathname: history.location.pathname,
|
|
3252
|
+
search
|
|
3253
|
+
});
|
|
3254
|
+
}
|
|
3270
3255
|
});
|
|
3271
3256
|
ctx.onConnected(() => {
|
|
3272
3257
|
history.listen(onRouteChange);
|
|
@@ -3286,8 +3271,7 @@ function RouterStore(ctx) {
|
|
|
3286
3271
|
const onRouteChange = async ({ location }) => {
|
|
3287
3272
|
if (location.search !== lastQuery) {
|
|
3288
3273
|
lastQuery = location.search;
|
|
3289
|
-
|
|
3290
|
-
$$query.set(parseQueryParams(location.search.startsWith("?") ? location.search.slice(1) : location.search));
|
|
3274
|
+
$$query.set(parseQueryParams(location.search));
|
|
3291
3275
|
}
|
|
3292
3276
|
const matched = matchRoutes(routes, location.pathname);
|
|
3293
3277
|
if (!matched) {
|
|
@@ -3399,6 +3383,9 @@ function RouterStore(ctx) {
|
|
|
3399
3383
|
joined = path.toString();
|
|
3400
3384
|
}
|
|
3401
3385
|
joined = resolvePath(history.location.pathname, joined);
|
|
3386
|
+
if (options.preserveQuery) {
|
|
3387
|
+
joined += history.location.search;
|
|
3388
|
+
}
|
|
3402
3389
|
if (options.replace) {
|
|
3403
3390
|
history.replace(joined);
|
|
3404
3391
|
} else {
|