You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -141,6 +141,7 @@ npm install --save dendriform
141
141
- [Rendering](#rendering)
142
142
- [Rendering arrays](#rendering-arrays)
143
143
- [Setting data](#setting-data)
144
+
- [Readonly forms](#readonly-forms)
144
145
- [Updating from props](#updating-from-props)
145
146
- [ES6 classes](#es6-classes)
146
147
- [ES6 maps](#es6-maps)
@@ -579,6 +580,23 @@ form.done();
579
580
// form.value will update to become 3
580
581
```
581
582
583
+
### Readonly forms
584
+
585
+
You may want to allow subscribers to a form, while also preventing them from making any changes. For this use case, the `readonly()` method returns a version of the form that cannot be set and cannot navigate history. Any forms branched off a readonly form will also be unable to set or navigate history.
586
+
587
+
```js
588
+
constform=newDendriform(0);
589
+
constreadonlyForm=form.readonly();
590
+
591
+
// readonlyForm can have its .value and .useValue read
592
+
// can subscribe to changes with .onChange() etc. and can render,
593
+
// but calling .set(), .go() or any derivatives
594
+
// will cause an error to be thrown
595
+
596
+
readonlyForm.set(1); // throws error
597
+
598
+
```
599
+
582
600
### Updating from props
583
601
584
602
The `useDendriform` hook can automatically update when props change. If a `dependencies` array is passed as an option, the dependencies are checked using `Object.is()` equality to determine if the form should update. If an update is required, the `value` function is called again and the form is set to the result.
Copy file name to clipboardExpand all lines: packages/dendriform/README.md
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -141,6 +141,7 @@ npm install --save dendriform
141
141
- [Rendering](#rendering)
142
142
- [Rendering arrays](#rendering-arrays)
143
143
- [Setting data](#setting-data)
144
+
- [Readonly forms](#readonly-forms)
144
145
- [Updating from props](#updating-from-props)
145
146
- [ES6 classes](#es6-classes)
146
147
- [ES6 maps](#es6-maps)
@@ -579,6 +580,23 @@ form.done();
579
580
// form.value will update to become 3
580
581
```
581
582
583
+
### Readonly forms
584
+
585
+
You may want to allow subscribers to a form, while also preventing them from making any changes. For this use case, the `readonly()` method returns a version of the form that cannot be set and cannot navigate history. Any forms branched off a readonly form will also be unable to set or navigate history.
586
+
587
+
```js
588
+
constform=newDendriform(0);
589
+
constreadonlyForm=form.readonly();
590
+
591
+
// readonlyForm can have its .value and .useValue read
592
+
// can subscribe to changes with .onChange() etc. and can render,
593
+
// but calling .set(), .go() or any derivatives
594
+
// will cause an error to be thrown
595
+
596
+
readonlyForm.set(1); // throws error
597
+
598
+
```
599
+
582
600
### Updating from props
583
601
584
602
The `useDendriform` hook can automatically update when props change. If a `dependencies` array is passed as an option, the dependencies are checked using `Object.is()` equality to determine if the form should update. If an update is required, the `value` function is called again and the form is set to the result.
0 commit comments