-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexamples-callbacks.js
More file actions
48 lines (37 loc) · 1.46 KB
/
examples-callbacks.js
File metadata and controls
48 lines (37 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// This example demonstrates backward compatibility
// All existing callback-based code continues to work exactly as before
const Filejson = require("./app.js");
console.log("=== Testing Backward Compatibility ===\n");
// Example 1: Original callback style still works
const file1 = new Filejson();
file1.load("callback-test.json", { original: "style", count: 0 }, function(error, file) {
if (error) {
console.error("Error:", error);
return;
}
console.log("1. Loaded with callback:", file.contents);
file.contents.count++;
file.contents.updated = true;
console.log("2. Modified:", file.contents);
// Manual save with callback also still works
file.save(function(saveError) {
if (saveError) {
console.error("Save error:", saveError);
return;
}
console.log("3. Saved successfully with callback!");
// Example 2: Without overwrite parameter
const file2 = new Filejson();
file2.load("callback-test.json", function(error, file) {
if (error) {
console.error("Error:", error);
return;
}
console.log("\n4. Re-loaded with callback (no overwrite):", file.contents);
// Delete a property
delete file.contents.updated;
console.log("5. After delete:", file.contents);
console.log("\n=== All backward compatibility tests passed! ===");
});
});
});