Last active
August 29, 2015 14:18
-
-
Save tel/ed88c2b9c007d990a99a to your computer and use it in GitHub Desktop.
Meteor Tracker Goji binding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Goji | |
let tracker_package = | |
register_package | |
~version:"1.0.7" | |
~doc:"Simple, push-based reactivity." | |
"tracker" | |
let tracker_component = | |
register_component | |
~version:"1.0.7" | |
~author:"Meteor Development Group" | |
~license:License.mit | |
~grabber:Grab.(sequence [ | |
http_get | |
"https://raw.githubusercontent.com/meteor/meteor/devel/packages/tracker/tracker.js" | |
"goji_entry.js" | |
]) | |
~binding_author:"Joseph Abrahamson <[email protected]>" | |
~binding_version:"1.0.7" | |
~doc:"Simple, push-based reactivity." | |
tracker_package "tracker" | |
[ | |
section "Tracker" | |
[ map_global "active" | |
~doc:"True if there is a current computation, meaning that \ | |
dependencies on reactive data sources will be tracked \ | |
and potentially cause the current computation to be rerun." | |
~read_only:true | |
(bool @@ global "Tracker.active") | |
; structure "Computation" | |
~doc:"A Computation object represents code that is repeatedly rerun \ | |
in response to reactive data changes. Computations don't have \ | |
return values; they just perform actions, such as rerendering \ | |
a template on the screen. Computations are created using \ | |
Tracker.autorun. Use stop to prevent further rerunning of a \ | |
computation." | |
[ def_type "t" (abstract any) | |
; map_attribute "t" "stopped" | |
~doc:"True if this computation has been stopped." | |
~read_only:true | |
bool | |
; map_attribute "t" "invalidated" | |
~doc:"True if this computation has been invalidated (and not yet \ | |
rerun), or if it has been stopped." | |
~read_only:true | |
bool | |
; map_attribute "t" "firstRun" | |
~doc:"True during the initial run of the computation at the time \ | |
[Tracker.autorun[ is called, and false on subsequent reruns \ | |
and at other times." | |
~rename:"first_run" | |
~read_only:true | |
bool | |
; map_method "t" "stop" | |
~doc:"Prevents this computation from rerunning." | |
[] void | |
; map_method "t" "invalidate" | |
~doc:"Invalidates this computation so that it will be rerun." | |
[] void | |
; map_method "t" "onInvalidate" | |
~doc:"Registers [callback] to run when this computation is next \ | |
invalidated, or runs it immediately if the computation is \ | |
already invalidated. The callback is run exactly once and \ | |
not upon future invalidations unless [onInvalidate[ is called \ | |
again after the computation becomes valid again." | |
[ curry_arg "callback" | |
~doc:"Function to be called on invalidation." | |
(callback | |
[ curry_arg "computation" | |
~doc:"The computation that was invalidated" | |
(abbrv "t" @@ arg 0) | |
] | |
void @@ arg 0) | |
] | |
void | |
] | |
; structure "Dependency" | |
~doc:"A Dependency represents an atomic unit of reactive data that a \ | |
computation might depend on. Reactive data sources such as Session or \ | |
Minimongo internally create different Dependency objects for different \ | |
pieces of data, each of which may be depended on by multiple computations. \ | |
When the data changes, the computations are invalidated." | |
[ def_type "t" (abstract any) | |
; map_constructor "t" "make" [] "Tracker.Dependency" | |
; map_method "t" "depend" | |
~doc:"Declares that the current computation depends on [dependency]. \ | |
The computation will be invalidated the next time [dependency] changes. \ | |
If there is no current computation it does nothing and returns false. \ | |
Returns true if the computation is a new dependent of [dependency] \ | |
rather than an existing one." | |
[] void | |
; map_method "t" "depend" | |
~rename:"depend_on" | |
~doc:"Declares that a computation depends on [dependency]. The computation will be \ | |
invalidated the next time [dependency] changes. Returns true if the computation \ | |
is a new dependent of [dependency] rather than an existing one." | |
[ curry_arg "computation" | |
~doc:"The dependent computation." | |
(abbrv "Computation.t" @@ arg 0)] void | |
; map_method "t" "changed" | |
~doc:"Invalidate all dependent computations immediately and remove \ | |
them as dependents." | |
[] void | |
; map_method "t" "hasDependents" | |
~rename:"has_dependents" | |
~doc:"True if this Dependency has one or more dependent Computations, \ | |
which would be invalidated if this Dependency were to change." | |
[] bool | |
] | |
; map_global "current_computation" | |
~doc:"The current computation, or [null] if there isn't one. \ | |
The current computation is the [Tracker.Computation] \ | |
object created by the innermost active call to \ | |
[Tracker.autorun], and it's the computation that gains \ | |
dependencies when reactive data sources are accessed." | |
~read_only:true | |
(option_null (abbrv "Computation.t") @@ global "Tracker.currentComputation") | |
; map_function "autorun" | |
~doc:"Run a function now and rerun it later whenever its dependencies \ | |
change. Returns a Computation object that can be used to stop or \ | |
observe the rerunning." | |
[ curry_arg "runFunc" | |
~doc:"The function to run. It receives one argument: the Computation \ | |
object that will be returned." | |
(callback | |
[ curry_arg "computation" | |
~doc:"The current computation" | |
(abbrv "Computation.t" @@ arg 0) | |
] | |
void @@ arg 0) ] | |
"Tracker.autorun" (abbrv "Computation.t") | |
; map_function "non_reactive" | |
~doc:"Run [f] with no current computation, returning the return value of \ | |
[f]. Used to turn off reactivity for the duration of [f], so that \ | |
reactive data sources accessed by [f] will not result in any \ | |
computations being invalidated." | |
[ curry_arg "runFunc" | |
~doc:"A function to call immediately, non-reactively." | |
(callback [] (param "'a") @@ arg 0) | |
] | |
"Tracker.nonreactive" (param "'a") | |
; map_function "on_invalidate" | |
~doc:"Registers a new [onInvalidate] callback on the current computation \ | |
(which must exist), to be called immediately when the current \ | |
computation is invalidated or stopped." | |
[ curry_arg "callback" | |
~doc:"Function to be called on invalidation." | |
(callback | |
[ curry_arg "computation" | |
~doc:"The computation that was invalidated" | |
(abbrv "Computation.t" @@ arg 0) | |
] | |
void @@ arg 0) | |
] | |
"Tracker.onInvalidate" void | |
; map_function "after_flush" | |
~doc:"Schedules a function to be called during the next flush, or \ | |
later in the current flush if one is in progress, after all \ | |
invalidated computations have been rerun. The function will \ | |
be run once and not on subsequent flushes unless \ | |
[afterFlush] is called again." | |
[ curry_arg "runFunc" | |
~doc:"A function to call immediately, non-reactively." | |
(callback [] void @@ arg 0) | |
] | |
"Tracker.afterFlush" void | |
] | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(** Simple, push-based reactivity. | |
This Binding for the JavaScript library Tracker version 1.0.7 by Meteor | |
Development Group has been automatically generated by the Goji binding | |
generator. It should not be edited by hand. | |
It is licensed under the MIT License (respecting the original library | |
license). See the LICENSE file for more details. *) | |
(** {2 Tracker} *) | |
(** True if there is a current computation, meaning that dependencies on | |
reactive data sources will be tracked and potentially cause the current | |
computation to be rerun. *) | |
val active : unit -> bool | |
(** A Computation object represents code that is repeatedly rerun in | |
response to reactive data changes. Computations don't have return | |
values; they just perform actions, such as rerendering a template on the | |
screen. Computations are created using Tracker.autorun. Use stop to | |
prevent further rerunning of a computation. *) | |
module Computation : sig | |
type t | |
(**/**) | |
val inject_t : t -> Goji_internal.any | |
val extract_t : Goji_internal.any -> t | |
(**/**) | |
(** True if this computation has been stopped. | |
Example call: [stopped this] | |
@param this The [t] instance *) | |
val stopped : t -> bool | |
(** True if this computation has been invalidated (and not yet rerun), | |
or if it has been stopped. | |
Example call: [invalidated this] | |
@param this The [t] instance *) | |
val invalidated : t -> bool | |
(** True during the initial run of the computation at the time | |
[Tracker.autorun[ is called, and false on subsequent reruns and at other | |
times. | |
Example call: [first_run this] | |
@param this The [t] instance *) | |
val first_run : t -> bool | |
(** Prevents this computation from rerunning. | |
Example call: [stop this] | |
@param this The [t] instance *) | |
val stop : t -> unit | |
(** Invalidates this computation so that it will be rerun. | |
Example call: [invalidate this] | |
@param this The [t] instance *) | |
val invalidate : t -> unit | |
(** Registers [callback] to run when this computation is next | |
invalidated, or runs it immediately if the computation is already | |
invalidated. The callback is run exactly once and not upon future | |
invalidations unless [onInvalidate[ is called again after the | |
computation becomes valid again. | |
Example call: [onInvalidate this callback] | |
@param this The [t] instance | |
@param callback Function to be called on invalidation. *) | |
val onInvalidate : t -> (t -> unit) -> unit | |
end | |
(** A Dependency represents an atomic unit of reactive data that a | |
computation might depend on. Reactive data sources such as Session or | |
Minimongo internally create different Dependency objects for different | |
pieces of data, each of which may be depended on by multiple | |
computations. When the data changes, the computations are invalidated. *) | |
module Dependency : sig | |
type t | |
(**/**) | |
val inject_t : t -> Goji_internal.any | |
val extract_t : Goji_internal.any -> t | |
(**/**) | |
val make : unit -> t | |
(** Declares that the current computation depends on [dependency]. The | |
computation will be invalidated the next time [dependency] changes. If | |
there is no current computation it does nothing and returns false. | |
Returns true if the computation is a new dependent of [dependency] | |
rather than an existing one. | |
Example call: [depend this] | |
@param this The [t] instance *) | |
val depend : t -> unit | |
(** Declares that a computation depends on [dependency]. The computation | |
will be invalidated the next time [dependency] changes. Returns true if | |
the computation is a new dependent of [dependency] rather than an | |
existing one. | |
Example call: [depend_on this computation] | |
@param this The [t] instance | |
@param computation The dependent computation. *) | |
val depend_on : t -> Computation.t -> unit | |
(** Invalidate all dependent computations immediately and remove them as | |
dependents. | |
Example call: [changed this] | |
@param this The [t] instance *) | |
val changed : t -> unit | |
(** True if this Dependency has one or more dependent Computations, | |
which would be invalidated if this Dependency were to change. | |
Example call: [has_dependents this] | |
@param this The [t] instance *) | |
val has_dependents : t -> bool | |
end | |
(** The current computation, or [null] if there isn't one. The current | |
computation is the [Tracker.Computation] object created by the innermost | |
active call to [Tracker.autorun], and it's the computation that gains | |
dependencies when reactive data sources are accessed. *) | |
val current_computation : unit -> Computation.t option | |
(** Run a function now and rerun it later whenever its dependencies | |
change. Returns a Computation object that can be used to stop or observe | |
the rerunning. | |
Example call: [autorun runFunc] | |
@param runFunc The function to run. It receives one argument: the | |
Computation object that will be returned. *) | |
val autorun : (Computation.t -> unit) -> Computation.t | |
(** Run [f] with no current computation, returning the return value of | |
[f]. Used to turn off reactivity for the duration of [f], so that | |
reactive data sources accessed by [f] will not result in any | |
computations being invalidated. | |
Example call: [non_reactive runFunc] | |
@param runFunc A function to call immediately, non-reactively. *) | |
val non_reactive : (unit -> 'a) -> 'a | |
(** Registers a new [onInvalidate] callback on the current computation | |
(which must exist), to be called immediately when the current | |
computation is invalidated or stopped. | |
Example call: [on_invalidate callback] | |
@param callback Function to be called on invalidation. *) | |
val on_invalidate : (Computation.t -> unit) -> unit | |
(** Schedules a function to be called during the next flush, or later in | |
the current flush if one is in progress, after all invalidated | |
computations have been rerun. The function will be run once and not on | |
subsequent flushes unless [afterFlush] is called again. | |
Example call: [after_flush runFunc] | |
@param runFunc A function to call immediately, non-reactively. *) | |
val after_flush : (unit -> unit) -> unit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment