@craftguild/jscalendar 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,13 +62,47 @@ const task = new JsCal.Task({
|
|
|
62
62
|
|
|
63
63
|
### Group
|
|
64
64
|
|
|
65
|
+
`entries` accepts either plain JSCalendar objects (including `eject()` results)
|
|
66
|
+
or `JsCal.Event`/`JsCal.Task` instances.
|
|
67
|
+
|
|
65
68
|
```ts
|
|
66
69
|
const group = new JsCal.Group({
|
|
67
70
|
title: "Project A",
|
|
68
|
-
entries: [event
|
|
71
|
+
entries: [event, task.eject()],
|
|
69
72
|
});
|
|
70
73
|
```
|
|
71
74
|
|
|
75
|
+
## Ejecting to plain objects
|
|
76
|
+
|
|
77
|
+
`JsCal.Event`/`JsCal.Task` are class instances with helper methods and a
|
|
78
|
+
`data` field that stores the RFC 8984 object. `eject()` returns a deep
|
|
79
|
+
clone of that underlying JSCalendar object for serialization, storage,
|
|
80
|
+
or passing across app boundaries.
|
|
81
|
+
|
|
82
|
+
Why `eject()` exists:
|
|
83
|
+
- Class instances are convenient for building and mutating objects with
|
|
84
|
+
helpers like `update`, `patch`, and `addParticipant`.
|
|
85
|
+
- External APIs, storage layers, and JSON stringify expect plain objects.
|
|
86
|
+
- A deep clone makes it safe to hand off data without accidental mutation
|
|
87
|
+
from the original instance (and vice versa).
|
|
88
|
+
|
|
89
|
+
What changes after `eject()`:
|
|
90
|
+
- You lose helper methods; the result is just a plain JSCalendar object.
|
|
91
|
+
- Mutating the plain object does not affect the original instance.
|
|
92
|
+
- The instance can still be used and updated independently.
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
const event = new JsCal.Event({ title: "Kickoff", start: "2026-02-02T10:00:00" });
|
|
96
|
+
const plain = event.eject();
|
|
97
|
+
|
|
98
|
+
// Plain object is ready for JSON / storage / network.
|
|
99
|
+
JSON.stringify(plain);
|
|
100
|
+
|
|
101
|
+
// Changes do not affect each other.
|
|
102
|
+
plain.title = "Exported";
|
|
103
|
+
event.update({ title: "Live" });
|
|
104
|
+
```
|
|
105
|
+
|
|
72
106
|
## Updates and Mutations
|
|
73
107
|
|
|
74
108
|
Mutation helpers update the underlying data and keep metadata such as
|