@react-brackets/core 2.0.0 → 2.0.1
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/dist/index.cjs +21 -7
- package/dist/index.js +21 -7
- package/package.json +6 -4
package/dist/index.cjs
CHANGED
|
@@ -93,13 +93,18 @@ function getMatch(stage, matchId) {
|
|
|
93
93
|
return match;
|
|
94
94
|
}
|
|
95
95
|
function mapMatches(stage, map) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
...
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
};
|
|
96
|
+
const groups = shared(stage.groups, (group) => {
|
|
97
|
+
const rounds = shared(group.rounds, (round) => {
|
|
98
|
+
const matches = shared(round.matches, map);
|
|
99
|
+
return matches === round.matches ? round : { ...round, matches };
|
|
100
|
+
});
|
|
101
|
+
return rounds === group.rounds ? group : { ...group, rounds };
|
|
102
|
+
});
|
|
103
|
+
return groups === stage.groups ? stage : { ...stage, groups };
|
|
104
|
+
}
|
|
105
|
+
function shared(items, map) {
|
|
106
|
+
const mapped = items.map(map);
|
|
107
|
+
return mapped.every((item, index) => item === items[index]) ? items : mapped;
|
|
103
108
|
}
|
|
104
109
|
function isComplete(stage) {
|
|
105
110
|
return allMatches(stage).every((match) => match.status === "completed" || match.status === "skipped");
|
|
@@ -135,6 +140,10 @@ function resolve(stage) {
|
|
|
135
140
|
return mapMatches(stage, (match) => visit(match.id));
|
|
136
141
|
}
|
|
137
142
|
function resolveMatch(match, visit) {
|
|
143
|
+
const next = settle(match, visit);
|
|
144
|
+
return next.status === match.status && next.winner === match.winner && next.slots[0] === match.slots[0] && next.slots[1] === match.slots[1] ? match : next;
|
|
145
|
+
}
|
|
146
|
+
function settle(match, visit) {
|
|
138
147
|
const slots = [
|
|
139
148
|
resolveSlot(match.slots[0], visit),
|
|
140
149
|
resolveSlot(match.slots[1], visit)
|
|
@@ -186,6 +195,9 @@ function resolveSlot(slot, visit) {
|
|
|
186
195
|
const outcome = outcomeOf(visit(slot.origin.matchId), slot.origin);
|
|
187
196
|
if (!outcome.decided)
|
|
188
197
|
return slot;
|
|
198
|
+
if (outcome.bye ? slot.bye && slot.participantId === null : !slot.bye && slot.participantId === outcome.participantId) {
|
|
199
|
+
return slot;
|
|
200
|
+
}
|
|
189
201
|
const { bye: _bye, ...rest } = slot;
|
|
190
202
|
return outcome.bye ? { ...rest, participantId: null, bye: true } : { ...rest, participantId: outcome.participantId };
|
|
191
203
|
}
|
|
@@ -198,6 +210,8 @@ function outcomeOf(match, origin) {
|
|
|
198
210
|
return { participantId: slot.participantId, bye: slot.bye === true, decided: true };
|
|
199
211
|
}
|
|
200
212
|
function clearScore(slot) {
|
|
213
|
+
if (!("score" in slot))
|
|
214
|
+
return slot;
|
|
201
215
|
const { score: _score, ...rest } = slot;
|
|
202
216
|
return rest;
|
|
203
217
|
}
|
package/dist/index.js
CHANGED
|
@@ -27,13 +27,18 @@ function getMatch(stage, matchId) {
|
|
|
27
27
|
return match;
|
|
28
28
|
}
|
|
29
29
|
function mapMatches(stage, map) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
...
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
};
|
|
30
|
+
const groups = shared(stage.groups, (group) => {
|
|
31
|
+
const rounds = shared(group.rounds, (round) => {
|
|
32
|
+
const matches = shared(round.matches, map);
|
|
33
|
+
return matches === round.matches ? round : { ...round, matches };
|
|
34
|
+
});
|
|
35
|
+
return rounds === group.rounds ? group : { ...group, rounds };
|
|
36
|
+
});
|
|
37
|
+
return groups === stage.groups ? stage : { ...stage, groups };
|
|
38
|
+
}
|
|
39
|
+
function shared(items, map) {
|
|
40
|
+
const mapped = items.map(map);
|
|
41
|
+
return mapped.every((item, index) => item === items[index]) ? items : mapped;
|
|
37
42
|
}
|
|
38
43
|
function isComplete(stage) {
|
|
39
44
|
return allMatches(stage).every((match) => match.status === "completed" || match.status === "skipped");
|
|
@@ -69,6 +74,10 @@ function resolve(stage) {
|
|
|
69
74
|
return mapMatches(stage, (match) => visit(match.id));
|
|
70
75
|
}
|
|
71
76
|
function resolveMatch(match, visit) {
|
|
77
|
+
const next = settle(match, visit);
|
|
78
|
+
return next.status === match.status && next.winner === match.winner && next.slots[0] === match.slots[0] && next.slots[1] === match.slots[1] ? match : next;
|
|
79
|
+
}
|
|
80
|
+
function settle(match, visit) {
|
|
72
81
|
const slots = [
|
|
73
82
|
resolveSlot(match.slots[0], visit),
|
|
74
83
|
resolveSlot(match.slots[1], visit)
|
|
@@ -120,6 +129,9 @@ function resolveSlot(slot, visit) {
|
|
|
120
129
|
const outcome = outcomeOf(visit(slot.origin.matchId), slot.origin);
|
|
121
130
|
if (!outcome.decided)
|
|
122
131
|
return slot;
|
|
132
|
+
if (outcome.bye ? slot.bye && slot.participantId === null : !slot.bye && slot.participantId === outcome.participantId) {
|
|
133
|
+
return slot;
|
|
134
|
+
}
|
|
123
135
|
const { bye: _bye, ...rest } = slot;
|
|
124
136
|
return outcome.bye ? { ...rest, participantId: null, bye: true } : { ...rest, participantId: outcome.participantId };
|
|
125
137
|
}
|
|
@@ -132,6 +144,8 @@ function outcomeOf(match, origin) {
|
|
|
132
144
|
return { participantId: slot.participantId, bye: slot.bye === true, decided: true };
|
|
133
145
|
}
|
|
134
146
|
function clearScore(slot) {
|
|
147
|
+
if (!("score" in slot))
|
|
148
|
+
return slot;
|
|
135
149
|
const { score: _score, ...rest } = slot;
|
|
136
150
|
return rest;
|
|
137
151
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-brackets/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Framework-agnostic tournament model: formats, results and layout.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Mohammed AlOulabi",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"url": "git+https://github.com/MohOulabi/react-brackets.git",
|
|
10
10
|
"directory": "packages/core"
|
|
11
11
|
},
|
|
12
|
-
"homepage": "https://
|
|
12
|
+
"homepage": "https://react-brackets.oulabi.dev",
|
|
13
13
|
"keywords": [
|
|
14
14
|
"tournament",
|
|
15
15
|
"bracket",
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
"swiss"
|
|
20
20
|
],
|
|
21
21
|
"type": "module",
|
|
22
|
-
"sideEffects":
|
|
22
|
+
"sideEffects": [
|
|
23
|
+
"./src/**"
|
|
24
|
+
],
|
|
23
25
|
"files": [
|
|
24
26
|
"dist"
|
|
25
27
|
],
|
|
@@ -40,7 +42,7 @@
|
|
|
40
42
|
"./package.json": "./package.json"
|
|
41
43
|
},
|
|
42
44
|
"scripts": {
|
|
43
|
-
"build": "NODE_ENV=production bunup",
|
|
45
|
+
"build": "NODE_ENV=production bunup && bun ../../scripts/assert-build.ts dist",
|
|
44
46
|
"dev": "bunup --watch",
|
|
45
47
|
"test": "bun test",
|
|
46
48
|
"typecheck": "tsc --noEmit",
|