Giter Club home page Giter Club logo

hydration's Introduction

hydration

A simple type registration and instance hydration library.

Usage Example

This library was originally created to solve type hydration from message buses, as loosely shown in the example below, but has a wide variety of usages in other problem spaces.

// During setup.
hydration.Register[event.CustomerCreated]()

// During message bus serialization.
message.TypeKey = hydration.DerivedTypeKey[event.CustomerCreated]()

// During message bus deserialization.
typeKey := message.TypeKey
e := hydration.ResolveWithKey[event.Event](typeKey)

Core Concepts

The unit of isolation in this package is the Registry. Users of this package can either create their own registry or use the global, default registry. Types are registered in registries using Type Keys, which are just strings used to look-up types.

There are 3 core operations exposed by this package:

  • Register a new type in a registry.
  • Resolve a concrete instance from a registry.
  • Know if a registry has a registration for a type key.

For each of these operations, there are 4 different variants:

  • Derived type key, default registry
  • Custom type key, default registry
  • Derived type key, custom registry
  • Custom type key, custom registry

For example, Register uses derived type keys and the default registry, but RegisterIntoWithKey allows a custom registry and type key to be specified.

hydration's People

Contributors

lukejoshuapark avatar

Stargazers

Scott Murray avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.