Skip to content

Commit a9b4110

Browse files
committed
Переход на новую идеологию 46
1 parent 8bbabac commit a9b4110

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "showcase3",
33
"author": "CourseIT",
4-
"version": "1.16.3",
4+
"version": "1.17.0",
55
"description": "showcase3",
66
"license": "GNU GENERAL PUBLIC LICENSE, Version 3",
77
"repository": {

src/library/URLMapper.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { reactive, watch, App } from "vue";
2-
import { LocationQuery, Router } from "vue-router";
3-
import { WatchStopHandle } from "vue";
1+
import { reactive, watch, App } from 'vue';
2+
import { LocationQuery, Router } from 'vue-router';
3+
import { WatchStopHandle } from 'vue';
44

55
interface DetailedFingerprint {
66
[key: string]: string | null;
@@ -9,15 +9,15 @@ function queryFingerprint(query: LocationQuery): {
99
fingerprint: string;
1010
detailedFingerprint: DetailedFingerprint;
1111
} {
12-
let fingerprint = "";
12+
let fingerprint = '';
1313
const detailedFingerprint: DetailedFingerprint = {};
1414
const keys = Object.keys(query).sort();
1515
for (const key_index in keys) {
1616
let key = keys[key_index];
1717
const value = query[key];
1818
key = encodeURIComponent(key);
1919
if (value == null) {
20-
fingerprint += "&" + key;
20+
fingerprint += '&' + key;
2121
detailedFingerprint[key] = null;
2222
continue;
2323
}
@@ -26,11 +26,11 @@ function queryFingerprint(query: LocationQuery): {
2626
? value.map((v) => v && encodeURIComponent(v))
2727
: [value && encodeURIComponent(value)];
2828
values.sort();
29-
let valueFingerprint = "";
29+
let valueFingerprint = '';
3030
for (let i = 0; i < values.length; i++) {
31-
valueFingerprint += "&" + key;
31+
valueFingerprint += '&' + key;
3232
if (values[i] != null) {
33-
valueFingerprint += "=" + values[i];
33+
valueFingerprint += '=' + values[i];
3434
}
3535
}
3636
fingerprint += valueFingerprint;
@@ -56,10 +56,7 @@ let detailedFingerprint: DetailedFingerprint = {};
5656
let watchers: { [key: string]: WatchStopHandle } = {};
5757

5858
function serializeChangedValue(key: string, value: object) {
59-
const s = JSON.stringify(
60-
value,
61-
arrModel.filter((param) => param.name === key)[0].props,
62-
);
59+
const s = JSON.stringify(value, arrModel.filter((param) => param.name === key)[0].props);
6360
if (_query.rawQuery[key] === s) {
6461
return;
6562
}
@@ -69,7 +66,7 @@ function serializeChangedValue(key: string, value: object) {
6966
fingerprint = actualFingerprint.fingerprint;
7067
detailedFingerprint = actualFingerprint.detailedFingerprint;
7168

72-
router["replace"]({ query: _query.rawQuery });
69+
router['replace']({ query: _query.rawQuery });
7370
}
7471
function setWatcher(key: string) {
7572
if (key in watchers) {
@@ -98,10 +95,7 @@ function handleRouteChange() {
9895
clearWatchers();
9996
}
10097

101-
function parseAndStoreQuery(
102-
query: LocationQuery,
103-
actualDetailedFingerprint: DetailedFingerprint,
104-
) {
98+
function parseAndStoreQuery(query: LocationQuery, actualDetailedFingerprint: DetailedFingerprint) {
10599
for (const key of Object.keys(query)) {
106100
if (detailedFingerprint[key] === actualDetailedFingerprint[key]) {
107101
continue;
@@ -113,7 +107,6 @@ function parseAndStoreQuery(
113107
} catch (
114108
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
115109
e
116-
/* eslint-disable-next-line no-empty */
117110
) {}
118111
}
119112
}
@@ -151,6 +144,7 @@ export type URLParam = {
151144
name: string;
152145
obj: URLObject;
153146
props: Array<string>;
147+
noneReactive?: boolean;
154148
};
155149

156150
let arrModel: Array<URLParam> = [];
@@ -162,7 +156,7 @@ export function useURLMapper(useModel: Array<URLParam>) {
162156
param.obj.setter(_query.query[param.name]);
163157
} else {
164158
param.props.forEach((prop: string) => {
165-
if (typeof _query.query[param.name] === "object") {
159+
if (typeof _query.query[param.name] === 'object') {
166160
param.obj[prop] = _query.query[param.name][prop];
167161
} else {
168162
param.obj[prop] = _query.query[param.name];
@@ -171,7 +165,10 @@ export function useURLMapper(useModel: Array<URLParam>) {
171165
}
172166
}
173167
_query.query[param.name] = param.obj;
174-
setWatcher(param.name);
168+
169+
if (!param.noneReactive) {
170+
setWatcher(param.name);
171+
}
175172
});
176173

177174
arrModel.push(...useModel);
@@ -181,6 +178,12 @@ export function useURLMapper(useModel: Array<URLParam>) {
181178
});
182179
}
183180

181+
export function saveURLMapper(names: Array<string>) {
182+
names.forEach((name: string) => {
183+
serializeChangedValue(name, _query.query[name]);
184+
});
185+
}
186+
184187
export function debugURLMapper(): ParsedQuery {
185188
return _query.query;
186189
}

0 commit comments

Comments
 (0)