MCPcopy Index your code
hub / github.com/4ian/GDevelop / withSerializationOptions

Function withSerializationOptions

newIDE/app/src/Utils/Serializer.js:27–43  ·  view source on GitHub ↗

* Helper to run a serialization callback with the canonical mode flag * temporarily enabled in the gd.Serializer. Always resets the flag, * even if `callback` throws. * * The flag is global to the gd.Serializer (and to the C++ side), so we must * be careful to reset it: leaving it on would sile

(
  options: ?SerializationOptions,
  callback: () => T
)

Source from the content-addressed store, hash-verified

25 * every subsequent serialization (including ones that don't expect it).
26 */
27function withSerializationOptions<T>(
28 options: ?SerializationOptions,
29 callback: () => T
30): T {
31 const useCanonical = !!(options && options.canonicalEventSerialization);
32 if (!useCanonical) {
33 return callback();
34 }
35
36 const previous = gd.Serializer.isCanonicalMode();
37 gd.Serializer.setCanonicalMode(true);
38 try {
39 return callback();
40 } finally {
41 gd.Serializer.setCanonicalMode(previous);
42 }
43}
44
45/**
46 * Tool function to save a serializable object to a JS object.

Callers 2

serializeToJSObjectFunction · 0.85
serializeToJSONFunction · 0.85

Calls 1

callbackFunction · 0.70

Tested by

no test coverage detected