models: some more cleanup.

db4
John Benediktsson 2014-11-29 23:00:24 -08:00
parent 439649e707
commit 4b1690b9c1
4 changed files with 22 additions and 16 deletions

View File

@ -1,6 +1,6 @@
! Copyright (C) 2008, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors models kernel sequences ;
USING: accessors kernel models sequences ;
IN: models.arrow
TUPLE: arrow < model quot ;
@ -8,11 +8,11 @@ TUPLE: arrow < model quot ;
: <arrow> ( model quot -- arrow )
f arrow new-model
swap >>quot
[ add-dependency ] keep ;
[ add-dependency ] keep ;
M: arrow model-changed
[ [ value>> ] [ quot>> ] bi* call( old -- new ) ] [ nip ] 2bi
set-model ;
[ [ value>> ] [ quot>> ] bi* call( old -- new ) ]
[ set-model ] bi ;
M: arrow model-activated
[ dependencies>> ] keep [ model-changed ] curry each ;

View File

@ -1,6 +1,6 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors models kernel sequences ;
USING: accessors kernel models sequences ;
IN: models.product
TUPLE: product < model ;
@ -26,7 +26,7 @@ M: product model-changed
M: product model-activated dup model-changed ;
M: product update-model
dup value>> swap [ set-model ] set-product-value ;
[ value>> ] keep [ set-model ] set-product-value ;
M: product range-value
[ range-value ] product-value ;

View File

@ -1,6 +1,6 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel models sequences ;
USING: accessors kernel locals models sequences ;
IN: models.history
TUPLE: history < model back forward ;
@ -14,11 +14,13 @@ TUPLE: history < model back forward ;
reset-history ;
: (add-history) ( history to -- )
swap value>> dup [ swap push ] [ 2drop ] if ;
swap value>> [ swap push ] [ drop ] if* ;
: go-back/forward ( history to from -- )
[ 2drop ]
[ [ dupd (add-history) ] dip pop swap set-model ] if-empty ;
:: go-back/forward ( history to from -- )
from empty? [
history to (add-history)
from pop history set-model
] unless ;
: go-back ( history -- )
dup [ forward>> ] [ back>> ] bi go-back/forward ;

View File

@ -1,15 +1,19 @@
USING: accessors models models.arrow inverse kernel ;
USING: accessors inverse kernel models models.arrow ;
IN: models.illusion
TUPLE: illusion < arrow ;
: <illusion> ( model quot -- illusion )
illusion new V{ } clone >>connections V{ } clone >>dependencies 0 >>ref
swap >>quot over >>model [ add-dependency ] keep ;
f illusion new-model
swap >>quot
over >>model
[ add-dependency ] keep ;
: <activated-illusion> ( model quot -- illusion ) <illusion> dup activate-model ;
: <activated-illusion> ( model quot -- illusion )
<illusion> dup activate-model ;
: backtalk ( value object -- )
[ quot>> [undo] call( a -- b ) ] [ model>> ] bi set-model ;
M: illusion update-model ( model -- ) [ [ value>> ] keep backtalk ] with-locked-model ;
M: illusion update-model ( model -- )
[ [ value>> ] keep backtalk ] with-locked-model ;