Skip to content

Redesign mechanism of bulk delegation of preset components #26

Description

@soareschen

Summary

At the moment, the mechanism for bulk delegation of preset components is still sub-optimal. To scale the use of CGP, we need to make it much easier to define component presets and combine multiple component presets.

New Syntax

The new preset macro would roughly have the following shape:

#[cgp_preset]
pub mod foo_preset {
  #[extend]
  use bar_crate::bar_preset;
  
  #[extend {
    exclude: [ BazTwoComponent ]
  }]
  use baz_crate::baz_preset;

  pub struct Components {
    FooOneComponent: FooOneImpl,
    FooTwoComponent: FooTwoImpl,
  }
}

Which would roughly expands to the following:

pub mod foo_preset {
  pub trait IsMember {}

  pub struct Components;

  bar_crate::bar_preset::with_components! {
    Name => {
      impl DelegateComponent<Name> for Components {
        type Delegate = bar_crate::bar_preset::Components;
      }
  
      impl IsMember for Name {}
    }
  }

  baz_crate::baz_preset::with_components! {
    exclude: [ BazTwoComponent ],
    Name => {
      impl DelegateComponent<Name> for Components {
        type Delegate = baz_crate::baz_preset::Components;
      }
  
      impl IsMember for Name {}
    }
  }

  impl DelegateComponent<FooOneComponent> for Components {
    type Delegate = FooOneImpl;
  }
  
  impl IsMember for FooOneComponent {}

  impl DelegateComponent<FooTwoComponent> for Components {
    type Delegate = FooTwoImpl;
  }
  
  impl IsMember for FooTwoComponent {}

  macro_rules with_components {
    ( $( $rest:tt )* ) => {
      cgp::prelude::for_each! {
        [ FooOneComponent, FooTwoComponent ],
        $( $rest )*
      }

      bar_crate::bar_preset::with_components! {
        $( $rest )*
      }

      baz_crate::baz_preset::with_components! {
        $( $rest )*
      }
    }
  }
}

Activity

  1. added this to the v1.0 Release milestone on Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions