Skip to content

Commit

Permalink
Merge pull request #15 from hyoo-ru/new-tree2
Browse files Browse the repository at this point in the history
$mol_view_tree2 refactor, hyoo-ru/mam_mol#646
  • Loading branch information
nin-jin committed Feb 11, 2024
2 parents 762222d + e2a751f commit 3b904c5
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
2 changes: 1 addition & 1 deletion component/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace $ {

@ $mol_mem
prop_names() {
return this.$.$mol_view_tree2_class_props( this.tree() ).map( tree => this.$.$mol_view_tree2_prop_split( tree ).name.text() )
return this.$.$mol_view_tree2_class_props( this.tree() ).map( tree => this.$.$mol_view_tree2_prop_parts( tree ).name )
}

@ $mol_mem
Expand Down
4 changes: 2 additions & 2 deletions studio.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ namespace $.$$ {
const all = new Map< string, $mol_tree2 >()

const add = ( prop: $mol_tree2 )=> {
const name = this.$.$mol_view_tree2_prop_split( prop ).name.text()
const name = this.$.$mol_view_tree2_prop_parts( prop ).name
all.set( name, prop )
}

Expand Down Expand Up @@ -262,7 +262,7 @@ namespace $.$$ {
@ $mol_mem
props() {
const props = this.prop_filtered().map( prop => {
const name = this.$.$mol_view_tree2_prop_split( prop ).name.text()
const name = this.$.$mol_view_tree2_prop_parts( prop ).name
return this.Prop( name )
} )
return props
Expand Down
3 changes: 2 additions & 1 deletion type/type.view.tree
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$hyoo_studio_type $mol_pick
tree?val $mol_tree2_empty
tree?val null $mol_tree2_empty
belong_to \
type? \
trigger_content /
<= Value $mol_paragraph title <= type_display \
<= Take_put_hack_icon $mol_icon_arrow_left_right_bold_outline
Expand Down
60 changes: 32 additions & 28 deletions type/type.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,32 +103,36 @@ namespace $.$$ {

@ $mol_mem
type( next? : string ) {

if( next !== undefined ) {

switch( next ) {
case '' : this.tree(null); break
case 'null' : this.tree( this.tree().struct('null') ); break
case 'boolean_true' : this.tree( this.tree().struct('true') ); break
case 'boolean_false' : this.tree( this.tree().struct('false') ); break
case 'number': this.tree( this.tree().struct('0') ); break
case 'number_nan': this.tree( this.tree().struct('+NaN') ); break
case 'number_infinity_negative': this.tree( this.tree().struct('-Infinity') ); break
case 'number_infinity_positive': this.tree( this.tree().struct('+Infinity') ); break
case 'text': this.tree( this.tree().data('') ); break
case 'list': this.tree( this.tree().struct( '/' ) ); break
case 'dict': this.tree( this.tree().struct( '*' ) ); break
case 'object': this.tree( this.tree().struct( '$mol_view', [ this.tree().kids[0] ?? this.tree().data( '' ) ] ) ); break
case 'bind': this.tree( this.tree().struct( '<=>', [ this.tree().kids[0] ?? this.tree().data( '' ) ] ) ); break
case 'get': this.tree( this.tree().struct( '<=', [ this.tree().kids[0] ?? this.tree().data( '' ) ] ) ); break
case 'put': this.tree( this.tree().struct( '=>', [ this.tree().kids[0] ?? this.tree().data( '' ) ] ) ); break
default : $mol_fail( new TypeError( `Unsupported type: ${ next }` ) )
}

this.showed(false)
const tree = this.tree()
if (! tree) throw new Error(`tree prop not provided`)
if (next === undefined) return $hyoo_studio_type_value(tree)

let val

switch( next ) {
case '' : val = null; break
case 'null' : val = tree.struct('null'); break
case 'boolean_true' : val = tree.struct('true'); break
case 'boolean_false' : val = tree.struct('false'); break
case 'number': val = tree.struct('0'); break
case 'number_nan': val = tree.struct('+NaN'); break
case 'number_infinity_negative': val = tree.struct('-Infinity'); break
case 'number_infinity_positive': val = tree.struct('+Infinity'); break
case 'text': val = tree.data(''); break
case 'list': val = tree.struct( '/' ); break
case 'dict': val = tree.struct( '*' ); break
case 'object': val = tree.struct( '$mol_view', [ tree.kids[0] ?? tree.data( '' ) ] ); break
case 'bind': val = tree.struct( '<=>', [ tree.kids[0] ?? tree.data( '' ) ] ); break
case 'get': val = tree.struct( '<=', [ tree.kids[0] ?? tree.data( '' ) ] ); break
case 'put': val = tree.struct( '=>', [ tree.kids[0] ?? tree.data( '' ) ] ); break
}

return $hyoo_studio_type_value(this.tree())
if (val === undefined) $mol_fail( new TypeError( `Unsupported type: ${ next }` ) )

const next_tree = this.tree(val)!
this.showed(false)

return $hyoo_studio_type_value(next_tree)
}

show_obj_select() {
Expand All @@ -140,10 +144,10 @@ namespace $.$$ {

if ( next !== undefined ) {
this.showed(false)
return this.tree(this.tree().struct( next )).type
return this.tree(this.tree()?.struct( next ))?.type ?? super.selected_class()
}

return this.tree()?.type
return this.tree()?.type ?? super.selected_class()
}

@ $mol_mem
Expand All @@ -156,8 +160,8 @@ namespace $.$$ {
const from_tree = this.tree(
next === undefined
? undefined
: this.tree().struct( '/' + next, this.tree().kids )
).type.slice( 1 )
: this.tree()?.struct( '/' + next, this.tree()?.kids ?? []) ?? null
)?.type.slice( 1 )

const focused = this.List_items_type().focused()

Expand Down
2 changes: 1 addition & 1 deletion value/bound/bound.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace $.$$ {
const val = this.tree()

if( next === undefined ) {
return this.$.$mol_view_tree2_prop_split( val.kids[ 0 ] ).name.text() || '...'
return this.$.$mol_view_tree2_prop_parts( val.kids[ 0 ] ).name || '...'
}

this.tree(
Expand Down

0 comments on commit 3b904c5

Please sign in to comment.