Skip to content

Commit

Permalink
add pre-compute handler
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelselleck committed Jan 26, 2024
1 parent 370bb50 commit c04fad9
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs
Submodule docs updated from c748d9 to 8569b2
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn instantiate_main_component() -> Rc<ComponentInstance> {
{% if handler.source_map_start_marker %}
{{handler.source_map_start_marker}}
{% endif %}
{%- if entry.0.content in ['pre_render','mount'] -%}
{%- if entry.0.content in ['pre_compute', 'pre_render','mount'] -%}
|properties, ctx|{
let properties = &mut *properties.as_ref().borrow_mut();
if let Some(mut synthesized_self) = properties.downcast_mut::<{{fully_qualified_properties_type}}>() {
Expand Down Expand Up @@ -88,7 +88,7 @@ pub fn instantiate_{{ snake_case_type_id }}(mut args: InstantiationArgs) -> Rc<C
{% if handler.source_map_start_marker %}
{{handler.source_map_start_marker}}
{% endif %}
{%- if entry.0.content in ['pre_render','mount'] -%}
{%- if entry.0.content in ['pre_compute', 'pre_render','mount'] -%}
|properties, ctx|{
let properties = &mut *properties.as_ref().borrow_mut();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ instantiate_{{ snake_case_type_id }}(
{% if entry.1.source_map_start_marker %}
{{entry.1.source_map_start_marker}}
{% endif %}
{%- if entry.0.content in ['pre_render','mount'] -%}
{%- if entry.0.content in ['pre_compute', 'pre_render','mount'] -%}
|properties, ctx|{

let properties = &mut *properties.as_ref().borrow_mut();
Expand Down
4 changes: 2 additions & 2 deletions pax-core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub struct HandlerRegistry {
pub context_menu_handlers: Vec<fn(Rc<RefCell<dyn Any>>, &NodeContext, ArgsContextMenu)>,
pub wheel_handlers: Vec<fn(Rc<RefCell<dyn Any>>, &NodeContext, ArgsWheel)>,
pub pre_render_handlers: Vec<fn(Rc<RefCell<dyn Any>>, &NodeContext)>,
pub pre_compute_handlers: Vec<fn(Rc<RefCell<dyn Any>>, &NodeContext)>,
pub mount_handlers: Vec<fn(Rc<RefCell<dyn Any>>, &NodeContext)>,
}

Expand Down Expand Up @@ -128,6 +129,7 @@ impl Default for HandlerRegistry {
checkbox_change_handlers: Vec::new(),
button_click_handlers: Vec::new(),
textbox_change_handlers: Vec::new(),
pre_compute_handlers: Vec::new(),
}
}
}
Expand Down Expand Up @@ -357,8 +359,6 @@ impl PaxEngine {
// completely remove once reactive properties dirty-dag is a thing.
//
self.root_node.recurse_update(&mut self.runtime_context);
self.root_node
.recurse_update_native_patches(&mut self.runtime_context);

// 2. LAYER-IDS, z-index list creation Will always be recomputed each
// frame. Nothing intensive is to be done here.
Expand Down
22 changes: 9 additions & 13 deletions pax-core/src/engine/expanded_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::Globals;
use core::fmt;
use std::any::Any;
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::{Rc, Weak};

use kurbo::Point;
Expand Down Expand Up @@ -215,13 +214,6 @@ impl ExpandedNode {
self.attach_children(new_children, context);
}

pub fn recurse_update_native_patches(&self, context: &mut RuntimeContext) {
self.instance_node.handle_native_patches(self, context);
for child in self.children.borrow().iter() {
child.recurse_update_native_patches(context);
}
}

/// This method recursively updates all node properties. When dirty-dag exists, this won't
/// need to be here since all property dependencies can be set up and removed during mount/unmount
pub fn recurse_update(self: &Rc<Self>, context: &mut RuntimeContext) {
Expand All @@ -243,16 +235,20 @@ impl ExpandedNode {
computed_tab: compute_tab(self, &viewport),
});

// This isn't really the right location for handle_render, but needs to be here
// for the current version of stacker to work correctly. When dirty-dag is a thing
// this can be called at any location since whatever properties it changes
// will immediately trigger the nessessary side effects
if let Some(ref registry) = self.instance_node.base().handler_registry {
for handler in &registry.borrow().pre_render_handlers {
for handler in &registry.borrow().pre_compute_handlers {
handler(Rc::clone(&self.properties), &self.get_node_context(context))
}
}
Rc::clone(&self.instance_node).update(&self, context);
if *self.attached.borrow() > 0 {
self.instance_node.handle_native_patches(self, context);
}
if let Some(ref registry) = self.instance_node.base().handler_registry {
for handler in &registry.borrow().pre_render_handlers {
handler(Rc::clone(&self.properties), &self.get_node_context(context))
}
}
for child in self.children.borrow().iter() {
child.recurse_update(context);
}
Expand Down
1 change: 1 addition & 0 deletions pax-language-server/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ lazy_static! {
("double_click", "Set Double Click event handler"),
("context_menu", "Set Context Menu event handler"),
("wheel", "Set Wheel event handler"),
("pre_compute", "Set Pre Compute event handler"),
("pre_render", "Set Will Render event handler"),
("mount", "Set Did Mount event handler"),
];
Expand Down
9 changes: 6 additions & 3 deletions pax-manifest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use serde_json;

/// Definition container for an entire Pax cartridge
#[derive(Serialize, Deserialize)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct PaxManifest {
pub components: HashMap<String, ComponentDefinition>,
pub main_component_type_id: String,
Expand Down Expand Up @@ -36,8 +37,8 @@ impl Ord for ExpressionSpec {
}
}

#[cfg_attr(debug_assertions, derive(Debug))]
#[derive(Serialize, Deserialize, Clone)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct ExpressionSpec {
/// Unique id for vtable entry — used for binding a node definition property to vtable
pub id: usize,
Expand Down Expand Up @@ -120,7 +121,8 @@ impl ExpressionSpecInvocation {

/// Container for an entire component definition — includes template, settings,
/// event bindings, property definitions, and compiler + reflection metadata
#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Serialize, Deserialize, Clone)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct ComponentDefinition {
pub type_id: String,
pub type_id_escaped: String,
Expand Down Expand Up @@ -285,7 +287,8 @@ impl PropertyDefinition {
}

/// Describes metadata surrounding a property's type, gathered from a combination of static & dynamic analysis
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[derive(Serialize, Deserialize, Clone, Default)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct TypeDefinition {
/// Program-unique ID for this type
pub type_id: String,
Expand Down
4 changes: 2 additions & 2 deletions pax-std/src/stacker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use pax_runtime_api::{NodeContext, PropertyLiteral};
}
@handlers {
pre_render: handle_pre_render
pre_compute: handle_pre_compute
}
)]
Expand Down Expand Up @@ -51,7 +51,7 @@ impl Default for Stacker {
}

impl Stacker {
pub fn handle_pre_render(&mut self, ctx: &NodeContext) {
pub fn handle_pre_compute(&mut self, ctx: &NodeContext) {
let cells = self.cells.get().get_as_float();
let bounds = ctx.bounds_self;

Expand Down

0 comments on commit c04fad9

Please sign in to comment.