Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign mechanism of bulk delegation of preset components #26

Open
soareschen opened this issue Dec 1, 2024 · 0 comments
Open

Redesign mechanism of bulk delegation of preset components #26

soareschen opened this issue Dec 1, 2024 · 0 comments
Milestone

Comments

@soareschen
Copy link
Collaborator

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 )*
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant