2 cached::{Cached, TemplateId},
3 cached_set::{CacheId, CachedSet},
10/// Common context available to all `Render` implementations.
12/// Notably, the `RenderContext` gives access to the bump arena that the virtual
13/// DOM should be allocated within. This is available via the `bump` field.
14pub struct RenderContext<'a> {
15 /// The underlying bump arena that virtual DOMs are rendered into.
20 /// use dodrio::RenderContext;
22 /// // Given a rendering context, allocate an i32 inside its bump arena.
23 /// fn foo<'a>(cx: &mut RenderContext<'a>) -> &'a mut i32 {
29 pub(crate) cached_set: &'a crate::RefCell<CachedSet>,
31 pub(crate) templates: &'a mut FxHashMap<TemplateId, Option<CacheId>>,
33 // Prevent exhaustive matching on the rendering context, so we can always
34 // add more members in a semver-compatible way.
38impl fmt::Debug for RenderContext<'_> {
39 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
40 f.debug_struct("RenderContext")
41 .field("bump", &self.bump)
46impl<'a> RenderContext<'a> {
47 pub_unstable_internal! {
50 cached_set: &'a crate::RefCell<CachedSet>,
51 templates: &'a mut FxHashMap<TemplateId, Option<CacheId>>
62 pub(crate) fn cache<F>(&mut self, pinned: bool, template: Option<CacheId>, f: F) -> CacheId
64 F: for<'b> FnOnce(&mut RenderContext<'b>) -> Node<'b>,
66 CachedSet::insert(self, pinned, template, f)
69 /// Get or create the cached template for `Cached<R>`.
70 pub(crate) fn template<R>(&mut self) -> Option<CacheId>
72 R: 'static + Default + for<'b> Render<'b>,
74 let template_id = Cached::<R>::template_id();
75 if let Some(cache_id) = self.templates.get(&template_id).cloned() {
79 // Prevent re-entrancy from infinite looping. Any attempts to get `R`'s
80 // template while constructing the template will simply fail to use the
81 // templated fast path.
82 self.templates.insert(template_id, None);
84 // Render the default `R` and save that as the template for all
86 let cache_id = self.cache(true, None, |nested_cx| R::default().render(nested_cx));
87 self.templates.insert(template_id, Some(cache_id));
92impl<'a, 'b> From<&'b RenderContext<'a>> for &'a Bump {
94 fn from(cx: &'b RenderContext<'a>) -> &'a Bump {
99impl<'a, 'b, 'c> From<&'c &'b mut RenderContext<'a>> for &'a Bump {
101 fn from(cx: &'c &'b mut RenderContext<'a>) -> &'a Bump {
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list