frp: switcher ignores f values

db4
Sam Anklesaria 2009-05-03 12:14:17 -05:00
parent bd92f6c8cc
commit 6fc5e7a754
2 changed files with 5 additions and 3 deletions

View File

@ -36,7 +36,7 @@ HELP: <fold>
{ $values { "oldval" "starting value" } { "quot" "applied to update and previous values" } { "model" model } { "model'" model } }
{ $description "Similar to " { $link reduce } " but works on models, applying a quotation to the previous and new values at each update" } ;
HELP: switch
HELP: <switch>
{ $values { "signal1" model } { "signal2" model } { "signal'" model } }
{ $description "Creates a model that starts with the behavior of model1 and switches to the behavior of model2 on its update" } ;

View File

@ -20,6 +20,8 @@ M: frp-table row-color color-quot>> [ call( a -- b ) ] [ drop f ] if* ;
focus-border-color >>focus-border-color
transparent >>column-line-color ;
: <frp-list> ( model -- table ) <frp-table> [ 1array ] >>quot ;
: <frp-list*> ( -- table ) f <model> <frp-list> ;
: <frp-field> ( -- field ) f <model> <model-field> ;
! Layout utilities
@ -72,10 +74,10 @@ M: fold-model model-changed [ [ value>> ] [ [ oldval>> ] [ quot>> ] bi ] bi*
TUPLE: switch-model < multi-model original switcher on ;
M: switch-model model-changed 2dup switcher>> =
[ [ value>> ] [ t >>on ] bi* set-model ]
[ over value>> [ [ value>> ] [ t >>on ] bi* set-model ] [ 2drop ] if ]
[ dup on>> [ 2drop ] [ [ value>> ] dip set-model ] if ] if ;
M: switch-model model-activated [ original>> ] keep model-changed ;
: switch ( signal1 signal2 -- signal' ) [ 2array switch-model <multi-model> ] 2keep
: <switch> ( signal1 signal2 -- signal' ) [ 2array switch-model <multi-model> ] 2keep
[ >>original ] [ >>switcher ] bi* ;
TUPLE: mapped < model model quot ;