Skip to content

Commit 65eb326

Browse files
Review
1 parent b720b69 commit 65eb326

2 files changed

Lines changed: 34 additions & 28 deletions

File tree

packages/dev-playground/src/Main.res

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -832,23 +832,20 @@ module App = {
832832
}
833833

834834
let share = async () => {
835-
try {
836-
let _ = await UrlState.copyUrlState(
837-
Signal.peek(source),
838-
Signal.peek(compilerVersion),
839-
Signal.peek(moduleSystem),
840-
Signal.peek(warnFlags),
841-
Signal.peek(jsxPreserveMode),
842-
Signal.peek(experimentalFeatures),
843-
)
844-
showToast("Link copied")
845-
} catch {
846-
| JsExn(_) => showToast("Could not copy link")
847-
| _ => showToast("Could not copy link")
835+
switch await UrlState.copyUrlState(
836+
Signal.peek(source),
837+
Signal.peek(compilerVersion),
838+
Signal.peek(moduleSystem),
839+
Signal.peek(warnFlags),
840+
Signal.peek(jsxPreserveMode),
841+
Signal.peek(experimentalFeatures),
842+
) {
843+
| Ok() => showToast("Link copied")
844+
| Error(message) => showToast(message)
848845
}
849846
}
850847

851-
share()->ignore
848+
share()->Promise.ignore
852849
}
853850

854851
let loadCompiler = (version, compileAfterLoad) => {

packages/dev-playground/src/UrlState.res

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -241,19 +241,28 @@ let copyUrlState = async (
241241
warnFlags,
242242
jsxPreserveMode,
243243
experimentalFeatures,
244-
) => {
245-
replaceSequence := replaceSequence.contents + 1
246-
let encoded = await encodeCode(source)
247-
applyUrlState(
248-
encoded,
249-
compilerVersion,
250-
moduleSystem,
251-
warnFlags,
252-
jsxPreserveMode,
253-
experimentalFeatures,
254-
)
244+
): result<unit, string> => {
245+
try {
246+
replaceSequence := replaceSequence.contents + 1
247+
let sequence = replaceSequence.contents
248+
let encoded = await encodeCode(source)
249+
if sequence === replaceSequence.contents {
250+
applyUrlState(
251+
encoded,
252+
compilerVersion,
253+
moduleSystem,
254+
warnFlags,
255+
jsxPreserveMode,
256+
experimentalFeatures,
257+
)
255258
256-
let href = windowHref()
257-
let _ = await copyText(href)
258-
href
259+
let href = windowHref()
260+
let _ = await copyText(href)
261+
Ok()
262+
} else {
263+
Error("Link changed before it could be copied")
264+
}
265+
} catch {
266+
| _ => Error("Could not copy link")
267+
}
259268
}

0 commit comments

Comments
 (0)