Expand description
General utilities that may be useful while building Perseus apps.
Structs
Represents a duration that can be computed relative to the current time.
This should be created through
PerseusDuration::into_computed
only.An error type for invalid durations.
Traits
A trait that represents anything we’ll accept for specifying durations
for revalidation. Anything that implements thus must be able to be
transformed into a
ComputedDuration
;Functions
Same as
cache_res
, but takes a function that returns a Result
, allowing
you to use ?
and the like inside your logic.Runs the given function once and then caches the result to the filesystem
for future execution. Think of this as filesystem-level memoizing. In
future, this will be broken out into its own crate and wrapped by Perseus.
The second parameter to this allows forcing the function to re-fetch data
every time, which is useful if you want to revalidate data or test
your fetching logic again. Note that a change to the logic will not trigger
a reload unless you make it do so. For this reason, it’s recommended to only
use this wrapper once you’ve tested your fetching logic.
Marks a checkpoint in the code and alerts any tests that it’s been reached
by creating an element that represents it. The preferred solution would be
emitting a DOM event, but the WebDriver specification currently doesn’t
support waiting on those (go figure). This will only create a custom element
if the
__PERSEUS_TESTING
JS global variable is set to true
.Gets the path prefix to apply in the browser. This uses the HTML
<base>
element, which would be required anyway to make Sycamore’s router co-operate
with a relative path hosting.Gets the path prefix to apply on the server. This uses the
PERSEUS_BASE_PATH
environment variable, which avoids hardcoding
something as changeable as this into the final binary. Hence however, that
variable must be the same as what’s set in <base>
(done automatically).
Trailing forward slashes will be trimmed automatically.