-
-
Notifications
You must be signed in to change notification settings - Fork 17
Closed
Description
Description
Currently, RRuleTemporal doesn't provide a way to create a modified copy of an existing rule instance. The options() method returns a reference to the internal options object, which can be mutated directly, but this approach has several issues:
- No way to clone an instance: There's no built-in method to create a copy of a rule with modified options
- React compatibility issues: Direct mutation doesn't trigger re-renders in React's state management
- Breaks immutability patterns: Goes against modern JavaScript best practices
Use Case Example (React)
const [rule, setRule] = useState(
new RRuleTemporal({
freq: "MONTHLY",
byMonthDay: [1],
dtstart,
count: 3,
})
);
// This doesn't work - mutates the object but React won't re-render
rule.options().byMonthDay = [3];
// Current workaround - verbose and error-prone
setRule(new RRuleTemporal({
...rule.options(),
byMonthDay: [3],
}));Proposed Solutions
Option 1: Add a clone() method
const rule2 = rule1.clone({ byMonthDay: [3] });Option 2: Add a with() method (similar to Temporal API)
const rule2 = rule1.with({ byMonthDay: [3] });Option 3: Make options() return a deep copy
This would prevent accidental mutations but still doesn't solve the cloning issue.
Additional Context
This library is built on Temporal API which follows immutable patterns. It would be consistent to apply similar principles to RRuleTemporal as well.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels