Skip to content

Commit 357df6b

Browse files
committed
fix(asset-bundle): fix "add manifest data" logic
ManifestDataSystem->addManifestData now return stream;
1 parent 9cdd2e0 commit 357df6b

File tree

1 file changed

+85
-37
lines changed

1 file changed

+85
-37
lines changed

src/asset_bundle/all/manifest/ManifestDataSystem.re

Lines changed: 85 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -92,50 +92,98 @@ module All = {
9292
};
9393

9494
module SAB = {
95-
let addManifestData = (dependencyRelation, (sabRelativePath, sab)) => {
96-
let manifestJsonUint8Array =
97-
All.buildManifestData(
98-
dependencyRelation,
99-
(sabRelativePath, sab),
100-
(hashId, dependencyRelation) =>
101-
({hashId, dependencyRelation}: SABType.manifest)
102-
)
103-
|> GenerateABUtils.buildJsonUint8Array;
104-
105-
All.generateAB(
106-
BufferUtils.alignedLength(sab |> ArrayBuffer.byteLength),
107-
manifestJsonUint8Array,
108-
sab,
109-
);
110-
};
95+
let addManifestData = (dependencyRelation, (sabRelativePath, sab)) =>
96+
All.buildManifestData(
97+
dependencyRelation,
98+
(sabRelativePath, sab),
99+
(hashId, dependencyRelation) =>
100+
({hashId, dependencyRelation}: SABType.manifest)
101+
)
102+
|> Most.map((manifestData: SABType.manifest) => {
103+
let manifestJsonUint8Array =
104+
manifestData |> GenerateABUtils.buildJsonUint8Array;
105+
106+
(
107+
manifestData.hashId,
108+
sabRelativePath,
109+
All.generateAB(
110+
BufferUtils.alignedLength(sab |> ArrayBuffer.byteLength),
111+
manifestJsonUint8Array,
112+
sab,
113+
),
114+
);
115+
});
111116
};
112117

113118
module RAB = {
114-
let addManifestData = (dependencyRelation, (rabRelativePath, rab)) => {
115-
let manifestJsonUint8Array =
116-
All.buildManifestData(
117-
dependencyRelation,
118-
(rabRelativePath, rab),
119-
(hashId, dependencyRelation) =>
120-
({hashId, dependencyRelation}: RABType.manifest)
121-
)
122-
|> GenerateABUtils.buildJsonUint8Array;
123-
124-
All.generateAB(
125-
BufferUtils.alignedLength(rab |> ArrayBuffer.byteLength),
126-
manifestJsonUint8Array,
127-
rab,
128-
);
129-
};
119+
let addManifestData = (dependencyRelation, (rabRelativePath, rab)) =>
120+
All.buildManifestData(
121+
dependencyRelation,
122+
(rabRelativePath, rab),
123+
(hashId, dependencyRelation) =>
124+
({hashId, dependencyRelation}: RABType.manifest)
125+
)
126+
|> Most.map((manifestData: RABType.manifest) => {
127+
let manifestJsonUint8Array =
128+
manifestData |> GenerateABUtils.buildJsonUint8Array;
129+
130+
(
131+
manifestData.hashId,
132+
rabRelativePath,
133+
All.generateAB(
134+
BufferUtils.alignedLength(rab |> ArrayBuffer.byteLength),
135+
manifestJsonUint8Array,
136+
rab,
137+
),
138+
);
139+
});
130140
};
131141

132142
let addManifestData =
133143
(
134144
dependencyRelation: DependencyDataType.dependencyRelation,
135145
(sabDataArr, rabDataArr),
136-
) => (
137-
sabDataArr
138-
|> Js.Array.map(data => SAB.addManifestData(dependencyRelation, data)),
146+
) => {
147+
let wholeHashIdMap = WonderCommonlib.ImmutableHashMapService.createEmpty();
148+
139149
rabDataArr
140-
|> Js.Array.map(data => RAB.addManifestData(dependencyRelation, data)),
141-
);
150+
|> Js.Array.map(data => RAB.addManifestData(dependencyRelation, data))
151+
|> Most.mergeArray
152+
|> Most.reduce(
153+
((wholeHashIdMap, newRabDataArr), (hashId, rabRelativePath, rab)) => (
154+
wholeHashIdMap
155+
|> WonderCommonlib.ImmutableHashMapService.set(
156+
rabRelativePath,
157+
hashId,
158+
),
159+
newRabDataArr |> ArrayService.push(rab),
160+
),
161+
(
162+
WonderCommonlib.ImmutableHashMapService.createEmpty(),
163+
WonderCommonlib.ArrayService.createEmpty(),
164+
),
165+
)
166+
|> then_(((wholeHashIdMap, newRabDataArr)) =>
167+
sabDataArr
168+
|> Js.Array.map(data => SAB.addManifestData(dependencyRelation, data))
169+
|> Most.mergeArray
170+
|> Most.reduce(
171+
(
172+
(wholeHashIdMap, newSabDataArr),
173+
(hashId, sabRelativePath, sab),
174+
) => (
175+
wholeHashIdMap
176+
|> WonderCommonlib.ImmutableHashMapService.set(
177+
sabRelativePath,
178+
hashId,
179+
),
180+
newSabDataArr |> ArrayService.push(sab),
181+
),
182+
(wholeHashIdMap, WonderCommonlib.ArrayService.createEmpty()),
183+
)
184+
|> then_(((wholeHashIdMap, newSabDataArr)) =>
185+
(wholeHashIdMap, newRabDataArr, newSabDataArr) |> resolve
186+
)
187+
)
188+
|> Most.fromPromise;
189+
};

0 commit comments

Comments
 (0)