Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$mol_form_draft public api #641

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions form/draft/draft.view.tree
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
$mol_form_draft $mol_form
model $mol_object2
changed false
value_str*? \
value_bool*? false
value_number*? 0
dictionary_bool*? *
list_string*? /string
value_changed* false
reset? null

20 changes: 10 additions & 10 deletions form/draft/draft.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ namespace $.$$ {
*/
export class $mol_form_draft extends $.$mol_form_draft {
@ $mol_mem_key
list_string( field: string, next? : readonly string[] | null ) {
override list_string( field: string, next? : readonly string[] | null ) {
return this.value( field, next )?.map(norm_string) ?? []
}

@ $mol_mem_key
dictionary_bool( field: string, next? : Record<string, boolean> | null ): Record<string, boolean> {
override dictionary_bool( field: string, next? : Record<string, boolean> | null ): Record<string, boolean> {
if (next) {
const prev = this.model_pick(field) as Record<string, boolean>
const normalized = {} as typeof next
Expand All @@ -52,17 +52,17 @@ namespace $.$$ {
}

@ $mol_mem_key
value_str( field: string, next? : string | null ) {
override value_str( field: string, next? : string | null ) {
return norm_string( this.value( field, next ) )
}

@ $mol_mem_key
value_numb( field: string, next? : boolean | null ) {
override value_number( field: string, next? : boolean | null ) {
return norm_number( this.value( field, next ) )
}

@ $mol_mem_key
value_bool( field: string, next? : boolean | null ) {
override value_bool( field: string, next? : boolean | null ) {
return norm_bool( this.value( field, next ) )
}

Expand All @@ -81,7 +81,7 @@ namespace $.$$ {
}

@ $mol_mem_key
value_changed(field: string) {
override value_changed(field: string) {
const next = this.state_pick(field)
const prev = this.model_pick(field)
const next_norm = normalize_val(prev, next)
Expand All @@ -95,20 +95,20 @@ namespace $.$$ {
}

@ $mol_mem
changed() {
override changed() {
return Object.keys(this.state()).some(field => this.value_changed(field))
}

submit_allowed() {
override submit_allowed() {
return this.changed() && super.submit_allowed()
}

reset(next?: unknown) {
override reset(next?: unknown) {
this.state(null)
}

@ $mol_action
submit( next? : Event ) {
override submit( next? : Event ) {

const tasks = Object.entries( this.state() ).map(
([ field, next ]) => () => {
Expand Down