Skip to content
This repository has been archived by the owner on Dec 19, 2021. It is now read-only.

Commit

Permalink
fix: fix optimizedField,optimizedOptional for magic number!
Browse files Browse the repository at this point in the history
update version;
  • Loading branch information
yyc-git committed May 13, 2021
1 parent e83ba0a commit 8071c77
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wonder-bs-json",
"version": "0.0.1",
"version": "0.0.2",
"description": "",
"homepage": "https://github.com/Wonder-Technology/Wonder-bs-json.js",
"license": "MIT",
Expand Down
6 changes: 4 additions & 2 deletions src/Json_decode.re
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ let field = (key, decode, json) =>
raise @@ DecodeError("Expected object, got " ++ _stringify(json));
};

let getFailValueForOptimized = () => -1000000;

let optimizedField = (key, decode, json) =>
if (Js.typeof(json) == "object"
&& ! Js.Array.isArray(json)
Expand All @@ -210,7 +212,7 @@ let optimizedField = (key, decode, json) =>
/* decode(value) */
/* | None => raise @@ DecodeError({j|Expected field '$(key)'|j}) */
| None =>
Obj.magic(1000)
Obj.magic(getFailValueForOptimized())
};
} else {
raise @@ DecodeError("Expected object, got " ++ _stringify(json));
Expand All @@ -233,7 +235,7 @@ let optional = (decode, json) =>

let optimizedOptional = (decode, json) => {
let result = decode(json);
result === Obj.magic(1000) ? None : result |. Some;
result === Obj.magic(getFailValueForOptimized()) ? None : result |. Some;
};

let oneOf = (decoders, json) => {
Expand Down

0 comments on commit 8071c77

Please sign in to comment.