-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(forms): dirty state * feat(form): fieldsNamed prop * chore: imrpove validation stories
- Loading branch information
Showing
7 changed files
with
187 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type ExtractReadonlyArrayKeys<T extends readonly any[]> = (T) extends readonly (infer P)[] ? P : never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ComputedRef, Ref } from 'vue' | ||
|
||
const isComputedRef = <T>(value: Ref<T>): value is ComputedRef<any> & { _setter: (v: T) => void} => { | ||
return typeof value === 'object' && '_setter' in value | ||
} | ||
|
||
// TODO: Maybe it is better to tweak useStateful | ||
/** | ||
* Do not watches for effect, but looking for computed ref setter triggered. | ||
* Used to track when component tries to update computed ref. | ||
* | ||
* @notice you likely want to watch when value is changed, not setter is called. | ||
*/ | ||
export const watchSetter = <T>(ref: Ref<T>, cb: (newValue: T) => void) => { | ||
if (!isComputedRef(ref)) { return } | ||
const originalSetter = ref._setter | ||
|
||
ref._setter = (newValue: T) => { | ||
cb(newValue) | ||
originalSetter(newValue) | ||
} | ||
} |