Skip to content

Commit

Permalink
Contexts definition moved from $mol_view to $mol_object.
Browse files Browse the repository at this point in the history
  • Loading branch information
nin--jin committed Oct 21, 2017
1 parent 212b81b commit 5eff16e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion demo/large/large.view.ts
Expand Up @@ -4,7 +4,7 @@ namespace $.$$ {
@ $mol_mem
context_sub() {
const context = this.context()
const subContext : $mol_view_context = Object.create( context )
const subContext : typeof context = Object.create( context )

subContext.$mol_view_visible_height = () => this.minimal_height()
subContext.$mol_view_visible_width = () => this.minimal_width()
Expand Down
2 changes: 1 addition & 1 deletion grid/grid.view.ts
Expand Up @@ -194,7 +194,7 @@ namespace $.$$ {
@ $mol_mem
context_sub( ) {
const context = this.context()
const subContext : $mol_view_context = Object.create( context )
const subContext : typeof context = Object.create( context )
subContext.$mol_scroll_top = ()=> context.$mol_scroll_top() - this.offset()
return subContext

Expand Down
2 changes: 1 addition & 1 deletion list/list.view.ts
Expand Up @@ -51,7 +51,7 @@ namespace $.$$ {
const child = sub[ i ]
if( child == null ) continue
if( child instanceof $mol_view ) {
child.context( this.row_context( i ) )
child.$ = this.row_context( i )
}
next.push( child )
}
Expand Down
7 changes: 7 additions & 0 deletions object/object.ts
@@ -1,7 +1,14 @@
namespace $ {

export type $mol_object_context = ( Window )&( typeof $.$$ )&( typeof $ )

export class $mol_object {

get $() {
const owner = this.object_owner()
return ( owner && owner.$ || $ ) as $mol_object_context
}

public static make< Instance >( this : { new() : Instance } , config : Partial< Instance > ) : Instance {
const instance = new this
for( let key in config ) instance[ key ] = config[ key ]
Expand Down
4 changes: 2 additions & 2 deletions scroll/scroll.view.ts
Expand Up @@ -84,7 +84,7 @@ namespace $.$$ {
@ $mol_mem
context_sub( ) {
const context = this.context()
const subContext : $mol_view_context = Object.create( context )
const subContext : typeof context = Object.create( context )
subContext.$mol_view_visible_height = ()=> {
const sizeWin = $mol_window.size()
const limit = context.$mol_view_visible_height()
Expand Down Expand Up @@ -116,7 +116,7 @@ namespace $.$$ {
const context = this.context_sub()
sub.forEach( child => {
if( child instanceof $mol_view ) {
child.context( context )
child.$ = context
}
} )

Expand Down
10 changes: 5 additions & 5 deletions view/view.ts
Expand Up @@ -4,7 +4,8 @@ namespace $ {
export namespace $$ { let $$ }
export namespace $mol { let $mol }

export type $mol_view_context = ( Window )&( typeof $.$$ )&( typeof $ )
/// Use $mol_object_context instead
export type $mol_view_context = $mol_object_context

export function $mol_view_visible_width() {
return $mol_window.size().width
Expand Down Expand Up @@ -60,10 +61,9 @@ namespace $ {
}

@ $mol_mem
context( next? : $mol_view_context ) {
return next || $ as any
context( next? : $mol_object_context ) {
return next || $ as $mol_object_context
}

get $() {
return this.context()
}
Expand Down Expand Up @@ -101,7 +101,7 @@ namespace $ {
const context = this.context_sub()
sub.forEach( child => {
if( child instanceof $mol_view ) {
child.context( context )
child.$ = context
}
} )

Expand Down

0 comments on commit 5eff16e

Please sign in to comment.