]> gitweb.factorcode.org Git - factor.git/blob - core/ui/models.facts
more sql changes
[factor.git] / core / ui / models.facts
1 IN: models
2 USING: help generic kernel ;
3
4 HELP: model
5 { $class-description "A mutable placeholder for a single value. When the value is changed, a sequence of connected objects are notified. Models have the following slots:"
6     { $list
7         { { $link model-value } " - the value of the model. Use " { $link set-model } " to change the value." }
8         { { $link model-connections } " - a sequence of objects implementing the " { $link model-changed } " generic word, to be notified when the model's value changes." }
9         { { $link model-dependencies } " - a sequence of models which should have this model added to their sequence of connections when activated." }
10         { { $link model-ref } " - a reference count tracking the number of models which depend on this one." }
11     }
12 "Other classes may delegate to " { $link model } "."
13 } ;
14
15 HELP: <model>
16 { $values { "value" object } { "model" "a new " { $link model } } }
17 { $description "Creates a new model with an initial value." } ;
18
19 HELP: add-dependency
20 { $values { "dep" model } { "model" model } }
21 { $description "Registers a dependency. When " { $snippet "model" } " is activated, it will be added to " { $snippet "dep" } "'s connections and notified when " { $snippet "dep" } " changes." }
22 { $notes "This word should not be called directly unless you are implementing your own model class." }
23 { $see-also remove-dependency activate-model deactivate-model } ;
24
25 HELP: remove-dependency
26 { $values { "dep" model } { "model" model } }
27 { $description "Unregisters a dependency." }
28 { $notes "This word should not be called directly unless you are implementing your own model class." }
29 { $see-also add-dependency activate-model deactivate-model } ;
30
31 HELP: model-activated
32 { $values { "model" model } }
33 { $contract "Called after a model has been activated." }
34 { $see-also activate-model deactivate-model } ;
35
36 HELP: activate-model
37 { $values { "model" model } }
38 { $description "Increments the reference count of the model. If it was previously zero, this model is added as a connection to all models registered as dependencies by " { $link add-dependency } "." }
39 { $warning "Calls to " { $link activate-model } " and " { $link deactivate-model } " should be balanced to keep the reference counting consistent, otherwise " { $link model-changed } " might be called at the wrong time or not at all." } ;
40
41 HELP: deactivate-model
42 { $values { "model" model } }
43 { $description "Decrements the reference count of the model. If it reaches zero, this model is removed as a connection from all models registered as dependencies by " { $link add-dependency } "." }
44 { $warning "Calls to " { $link activate-model } " and " { $link deactivate-model } " should be balanced to keep the reference counting consistent, otherwise " { $link model-changed } " might be called at the wrong time or not at all." } ;
45
46 HELP: model-changed
47 { $values { "observer" object } }
48 { $contract "Called to notify observers of a model that the model value has changed as a result of a call to " { $link set-model } ". Observers can be registered with " { $link add-connection } "." }
49 { $see-also remove-connection } ;
50
51 HELP: add-connection
52 { $values { "observer" object } { "model" model } }
53 { $contract "Registers an object interested in being notified of changes to the model's value. When the value is changed as a result of a call to " { $link set-model } ", the " { $link model-changed } " word is called on the observer." }
54 { $see-also remove-connection add-dependency } ;
55
56 HELP: remove-connection
57 { $values { "observer" object } { "model" model } }
58 { $contract "Unregisters an object no longer interested in being notified of changes to the model's value." }
59 { $see-also add-connection remove-dependency } ;
60
61 HELP: set-model
62 { $values { "value" object } { "model" model } }
63 { $description "Changes the value of a model and calls " { $link model-changed } " on all observers registered with " { $link add-connection } "." }
64 { $see-also change-model } ;
65
66 HELP: set-model-value ( value model -- )
67 { $values { "value" object } { "model" model } }
68 { $description "Changes the value of a model without notifying any observers registered with " { $link add-connection } "." }
69 { $notes "There are very few reasons for user code to call this word. Instead, call " { $link set-model } ", which notifies observers." }
70 { $see-also change-model } ;
71
72 HELP: change-model
73 { $values { "model" model } { "quot" "a quotation with stack effect " { $snippet "( obj -- newobj )" } } }
74 { $description "Applies the quotation to the current value of the model to yield a new value, then changes the value of the model to the new value, and calls " { $link model-changed } " on all observers registered with " { $link add-connection } "." }
75 { $see-also set-model } ;
76
77 HELP: (change-model)
78 { $values { "model" model } { "quot" "a quotation with stack effect " { $snippet "( obj -- newobj )" } } }
79 { $description "Applies the quotation to the current value of the model to yield a new value, then changes the value of the model to the new value without notifying any observers registered with " { $link add-connection } "." }
80 { $notes "There are very few reasons for user code to call this word. Instead, call " { $link change-model } ", which notifies observers." }
81 { $see-also set-model } ;
82
83 HELP: delegate>model
84 { $values { "tuple" tuple } }
85 { $description
86     "Sets the tuple's delegate to a new " { $link model } " with an initial value of " { $link f } "."
87 } ;
88
89 HELP: filter
90 { $class-description "Filter model values are computed by applying a quotation to the value of another model. Filters are automatically updated when the underlying model changes. Filters are constructed by " { $link <filter> } "." } ;
91
92 HELP: <filter>
93 { $values { "model" model } { "quot" "a quotation with stack effect " { $snippet "( obj -- newobj )" } } { "filter" "a new " { $link filter } } }
94 { $description "Creates a new instance of " { $link filter } ". The value of the new filter model is computed by applying the quotation to the value." } ;
95
96 HELP: compose
97 { $class-description "Compose model values are computed by collecting the values from a sequence of underlying models into a new sequence. Compose models are automatically updated when underlying models change. Compose models are constructed by " { $link <compose> } "." } ;
98
99 HELP: <compose>
100 { $values { "models" "a sequence of models" } { "compose" "a new " { $link compose } } }
101 { $description "Creates a new instance of " { $link compose } ". The value of the new compose model is obtained by mapping " { $link model-value } " over the given sequence of models." } ;
102
103 HELP: history
104 { $class-description "History models record a timeline of previous values on calls to " { $link add-history } ", and can travel back and forth on the timeline with " { $link go-back } " and " { $link go-forward } ". History models are constructed by " { $link <history> } "." } ;
105
106 HELP: <history>
107 { $values { "value" object } { "history" "a new " { $link history } } }
108 { $description "Creates a new history model with an initial value." }
109 { $see-also add-history go-back go-forward } ;
110
111 HELP: go-back
112 { $values { "history" history } }
113 { $description "Restores the previous value and calls " { $link model-changed } " on all observers registered with " { $link add-connection } "." }
114 { $see-also add-history go-forward } ;
115
116 HELP: go-forward
117 { $values { "history" history } }
118 { $description "Restores the value set prior to the last call to " { $link go-back } " and calls " { $link model-changed } " on all observers registered with " { $link add-connection } "." }
119 { $see-also add-history go-back } ;
120
121 HELP: add-history
122 { $values { "history" history } }
123 { $description "Adds the current value to the history." } ;
124
125 HELP: delay
126 { $class-description "Delay models have the same value as their underlying model, however the value only changes after a timer expires. If the underlying model's value changes again before the timer expires, the timer restarts. Delay models are constructed by " { $link <delay> } "." } ;
127
128 HELP: <delay>
129 { $values { "model" model } { "timeout" "a positive integer" } { "delay" delay } }
130 { $description "Creates a new instance of " { $link delay } ". A timer of " { $snippet "timeout" } " milliseconds must elapse from the time the underlying model last changed to when the delay model value is changed and its connections are notified." } ;