⚛️
UniFlux
  • Introduction
  • ❓Getting Started
    • What is UniFlux
    • Setup
  • 🧩Components
    • MonoFlux
    • MethodFluxAttribute
    • StateFluxAttribute
    • Extension Key
  • ⚠️Use Cases
    • Service Locator Alternative
    • Singleton Alternative
    • Messaging Alternative
    • Avoiding Prop Drilling
  • 📚Tutorials
    • How to use a custom Key?
    • How To See Subscriptions ?
    • 📽️(Video) How to Use UniFlux on Unity
  • Links and References
    • 🔗References
    • 🌍Unity Asset Store
    • 🎲Made With UniFlux
    • 📦Github
    • 😎About Me
Powered by GitBook
On this page
Edit on GitHub
  1. Components

Extension Key

The Extension Key is a name invented to refer to the class that handles the extensions of the data type that we want to use as a key, things like for example "KEY".Dispatch(); implies that a string type key is being used

By default we allow the use of string and int. But that doesn't stop you from wanting to include more key types, such as a custom enum.

Here is a simple example

//######################## 
// String Key
//######################## 
"StringKey".Dispatch();
"StringKey".Store();
"StringKey".DispatchState(true);
"StringKey".StoreState(false, OnFakeStateMethod);
"StringKey".IEnumerator();
"StringKey".Task();
private static async Task Example()
{
  await "StringKey"; // Calls "StringKey".Task();
}

//######################## 
// Int Key
//######################## 
42.Dispatch();
42.Store();
42.DispatchState(true);
42.StoreState(false, OnFakeStateMethod);
42.IEnumerator();
42.Task();
private static async Task Example()
{
  await 42; // Calls 42.Task();
}

//######################## 
// CustomEnumEvent Key
//######################## 
CustomEnumEvent.OnPlayerDead.Dispatch();
CustomEnumEvent.OnPlayerDead.Store();
CustomEnumEvent.OnPlayerDead.DispatchState(true);
CustomEnumEvent.OnPlayerDead.StoreState(false, OnFakeStateMethod);
CustomEnumEvent.OnPlayerDead.IEnumerator();
CustomEnumEvent.OnPlayerDead.Task();
private static async Task Example()
{
  await CustomEnumEvent.OnPlayerDead; // Calls CustomEnumEvent.OnPlayerDead.Task();
}

For more information about how to create your own Custom Key take a look here

Last updated 1 year ago

🧩
How to use a custom Key?