diff --git a/extra/store/store.factor b/extra/store/store.factor index 38c1d3a906..639b6d3fab 100644 --- a/extra/store/store.factor +++ b/extra/store/store.factor @@ -8,30 +8,26 @@ TUPLE: store path data ; C: store : save-store ( store -- ) - [ store-data ] keep store-path [ - [ - dup - [ >r drop [ get ] keep r> set-at ] curry assoc-each - ] keep serialize - ] with-stream ; + get-global dup store-data swap store-path + [ serialize ] with-stream ; : load-store ( path -- store ) dup exists? [ - dup [ - deserialize - ] with-stream + dup [ deserialize ] with-stream ] [ H{ } clone ] if ; -: store-variable ( default variable store -- ) - store-data 2dup at* [ - rot set-global 2drop - ] [ - drop >r 2dup set-global r> set-at - ] if ; - : define-store ( path id -- ) over >r [ >r resource-path load-store r> set-global ] 2curry r> add-init-hook ; + +: get-persistent ( key store -- value ) + get-global store-data at ; + +: set-persistent ( value key store -- ) + get-global [ store-data set-at ] keep save-store ; + +: init-persistent ( value key store -- ) + 2dup get-persistent [ 3drop ] [ set-persistent ] if ; diff --git a/extra/webapps/pastebin/pastebin.factor b/extra/webapps/pastebin/pastebin.factor index d49863b12a..7ea98b8ba1 100755 --- a/extra/webapps/pastebin/pastebin.factor +++ b/extra/webapps/pastebin/pastebin.factor @@ -10,9 +10,9 @@ TUPLE: pastebin pastes ; ! Persistence SYMBOL: store + "pastebin.store" store define-store - pastebin store get store-variable -: save-pastebin-store ( -- ) store get-global save-store ; + pastebin store init-persistent TUPLE: paste summary author channel mode contents date @@ -25,8 +25,11 @@ TUPLE: annotation summary author mode contents ; C: annotation +: get-pastebin ( -- pastebin ) + pastebin store get-persistent ; + : get-paste ( n -- paste ) - pastebin get pastebin-pastes nth ; + get-pastebin pastebin-pastes nth ; : show-paste ( n -- ) serving-html @@ -46,7 +49,7 @@ C: annotation [ [ show-paste ] "show-paste-quot" set [ new-paste ] "new-paste-quot" set - pastebin get "paste-list" render-component + get-pastebin "paste-list" render-component ] with-html-stream ; \ paste-list { } define-action @@ -55,7 +58,7 @@ C: annotation paste-n number>string [ show-paste ] curry quot-link ; : paste-feed ( -- entries ) - pastebin get pastebin-pastes [ + get-pastebin pastebin-pastes [ { paste-summary paste-link @@ -77,8 +80,8 @@ C: annotation : submit-paste ( summary author channel mode contents -- ) [ - \ pastebin get-global add-paste - save-pastebin-store + pastebin store get-persistent add-paste + store save-store ] keep paste-link permanent-redirect ; \ submit-paste { @@ -92,7 +95,7 @@ C: annotation : annotate-paste ( n summary author mode contents -- ) swap get-paste paste-annotations push - save-pastebin-store ; + store save-store ; \ annotate-paste { { "n" v-required v-number }