Adding and removing vocabs now updates all-vocabs-seq
parent
38cc644eca
commit
b79245dc6c
|
@ -74,8 +74,6 @@ SYMBOL: failures
|
||||||
|
|
||||||
SYMBOL: changed-vocabs
|
SYMBOL: changed-vocabs
|
||||||
|
|
||||||
[ f changed-vocabs set-global ] "tools.vocabs" add-init-hook
|
|
||||||
|
|
||||||
: changed-vocab ( vocab -- )
|
: changed-vocab ( vocab -- )
|
||||||
dup vocab changed-vocabs get and
|
dup vocab changed-vocabs get and
|
||||||
[ dup changed-vocabs get set-at ] [ drop ] if ;
|
[ dup changed-vocabs get set-at ] [ drop ] if ;
|
||||||
|
@ -287,3 +285,12 @@ MEMO: all-authors ( -- seq )
|
||||||
\ all-vocabs-seq reset-memoized
|
\ all-vocabs-seq reset-memoized
|
||||||
\ all-authors reset-memoized
|
\ all-authors reset-memoized
|
||||||
\ all-tags reset-memoized ;
|
\ all-tags reset-memoized ;
|
||||||
|
|
||||||
|
SINGLETON: cache-observer
|
||||||
|
|
||||||
|
M: cache-observer vocabs-changed drop reset-cache ;
|
||||||
|
|
||||||
|
[
|
||||||
|
f changed-vocabs set-global
|
||||||
|
cache-observer add-vocab-observer
|
||||||
|
] "tools.vocabs" add-init-hook
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2007, 2009 Eduardo Cavazos, Slava Pestov.
|
! Copyright (C) 2007, 2009 Eduardo Cavazos, Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors assocs strings kernel sorting namespaces
|
USING: accessors assocs strings kernel sorting namespaces
|
||||||
sequences definitions ;
|
sequences definitions init ;
|
||||||
IN: vocabs
|
IN: vocabs
|
||||||
|
|
||||||
SYMBOL: dictionary
|
SYMBOL: dictionary
|
||||||
|
@ -65,8 +65,24 @@ M: object vocab-main vocab vocab-main ;
|
||||||
|
|
||||||
M: f vocab-main ;
|
M: f vocab-main ;
|
||||||
|
|
||||||
|
SYMBOL: vocab-observers
|
||||||
|
|
||||||
|
GENERIC: vocabs-changed ( obj -- )
|
||||||
|
|
||||||
|
[ V{ } clone vocab-observers set-global ] "vocabs" add-init-hook
|
||||||
|
|
||||||
|
: add-vocab-observer ( obj -- )
|
||||||
|
vocab-observers get push ;
|
||||||
|
|
||||||
|
: remove-vocab-observer ( obj -- )
|
||||||
|
vocab-observers get delq ;
|
||||||
|
|
||||||
|
: notify-vocab-observers ( -- )
|
||||||
|
vocab-observers get [ vocabs-changed ] each ;
|
||||||
|
|
||||||
: create-vocab ( name -- vocab )
|
: create-vocab ( name -- vocab )
|
||||||
dictionary get [ <vocab> ] cache ;
|
dictionary get [ <vocab> ] cache
|
||||||
|
notify-vocab-observers ;
|
||||||
|
|
||||||
ERROR: no-vocab name ;
|
ERROR: no-vocab name ;
|
||||||
|
|
||||||
|
@ -99,7 +115,8 @@ M: string >vocab-link dup vocab [ ] [ <vocab-link> ] ?if ;
|
||||||
|
|
||||||
: forget-vocab ( vocab -- )
|
: forget-vocab ( vocab -- )
|
||||||
dup words forget-all
|
dup words forget-all
|
||||||
vocab-name dictionary get delete-at ;
|
vocab-name dictionary get delete-at
|
||||||
|
notify-vocab-observers ;
|
||||||
|
|
||||||
M: vocab-spec forget* forget-vocab ;
|
M: vocab-spec forget* forget-vocab ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue