Options
All
  • Public
  • Public/Protected
  • All
Menu

Registry toolkit

Want to keep track of and work with all fish of a specific type? Meet the RegistryFish pattern.

scalable, reuseable, composable, and maintainable

One thing that has come up quite a few times is the need to track all fish of a certain kind in someplace. You may have a fish representing a specific entity on your shop-floor. There are going to be many instances of this fish, one for each entity. Now, what if you wanted to show a list of all these entities somewhere?

The registry pattern will lead you to a data model that is scalable, reuseable, composable, and maintainable.

Read the blog post about registry fish at developer.actyx.com/blog

📦 Installation

Registry toolkit is available as an npm package.

npm install @actyx-contrib/registry

📖 Example / Tutorials

This library is made to reduce the code you write.

import { createRegistryFish, observeRegistry } from '../src'
import { ChatFish, EventType } from "./fish/chatFish"
import { Pond } from '@actyx/pond'

Pond.default().then(pond => {
  export const ChatRoomRegistryFish = createRegistryFish(ChatFish, EventType.message)

  observeRegistry(pond, ChatRoomRegistryFish, ChatFish)
    .subscribe(console.log)
})

You will find detailed examples here

You can access the full api documentation and related examples by visiting:

https://actyx-contrib.github.io/registry

🤓 Developer tools

Script Description
npm run clean Clean lib and coverage folders
npm run tsc Run TypeScript check
npm run tsc:watch Run TypeScript check watch mode
npm run build Build project
npm run build:watch Build project watch mode
npm run lint Check for lint issues
npm run lint:fix Check and automatically fix lint issues
npm run test Run Jest tests
npm run test:no-coverage Run Jest tests and exclude coverage report
npm run license:add Append license information to every relevant files
npm run license:check Check if license information is present on every relevant files
npm run license:check-dep Check the licenses for project dependencies and produce a summary

Index

Type aliases

PondLike

PondLike: { observe: Pond["observe"] } | Pond["observe"]

type to use the pondLike or the observe function it self

RegistryFishState

RegistryFishState: ReadonlyArray<FishName>

private and public state of the registry fish

RegistryOnEvent

RegistryOnEvent<E>: (payload: E) => "add" | "remove" | "ignore"

OnEventHandler for a registry fish

return:

  • 'add' will add the event source.name to the registry (only once)
  • 'remove' will remove the event source.name to the registry
  • 'ignore' registry will not change

example

const eventHandler: RegistryOnEvent<Event> = event => {
    switch (event.type) {
      case EventType.create:
        return 'add'
      case EventType.deleted:
        return 'remove'
      default:
        return 'ignore';
    }
  }

Type parameters

  • E

Type declaration

    • (payload: E): "add" | "remove" | "ignore"
    • Parameters

      • payload: E

      Returns "add" | "remove" | "ignore"

Functions

Const createRegistryFish

  • createRegistryFish<E>(entityFish: FishType<unknown, E, unknown>, addEventOrEventHandler: E["type"] | ReadonlyArray<E["type"]> | RegistryOnEvent<E>, removeEvent?: E["type"] | ReadonlyArray<E["type"]>): FishTypeImpl<ReadonlyArray<string & OpaqueTag<unique symbol>>, unknown, E, ReadonlyArray<string & OpaqueTag<unique symbol>>>
  • Create a Registry fish for a given fish type

    example

    const RegistryFish1 = createRegistryFish(ExampleFish, EventType.create)
    const RegistryFish2 = createRegistryFish(ExampleFish, EventType.create, EventType.deleted)
    const RegistryFish3 = createRegistryFish(ExampleFish, [EventType.create])
    const RegistryFish4 = createRegistryFish(ExampleFish, [EventType.create], [EventType.deleted])
    const RegistryFish5 = createRegistryFish(
      ExampleFish,
      event => {
        switch (event.type) {
          case EventType.create:
            return 'add'
          case EventType.deleted:
            return 'remove'
          default:
            return 'ignore';
        }
      }
    )

    Type parameters

    • E: { type: string }

    Parameters

    • entityFish: FishType<unknown, E, unknown>

      Fish to create the registry for

    • addEventOrEventHandler: E["type"] | ReadonlyArray<E["type"]> | RegistryOnEvent<E>

      EventType or array of EventTypes to add the source.name to the registry or an eventHandler for more complex registry use-cases

    • Default value removeEvent: E["type"] | ReadonlyArray<E["type"]> = []

      EventType or array of EventTypes, when the source.name should be removed from the registry

    Returns FishTypeImpl<ReadonlyArray<string & OpaqueTag<unique symbol>>, unknown, E, ReadonlyArray<string & OpaqueTag<unique symbol>>>

Const observeAll

  • observeAll<P, E>(pond: PondLike, entityFish: FishType<unknown, E, P>, addEventOrEventHandler: E["type"] | ReadonlyArray<E["type"]> | RegistryOnEvent<E>, removeEvent?: E["type"] | ReadonlyArray<E["type"]>): Observable<ReadonlyArray<P>>
  • create an internal registry fish and return a stream of the state of all referenced entryFish as array

    Example

    const registryFish1 = observeAll(pond, ExampleFish, EventType.create)
    const registryFish2 = observeAll(pond, ExampleFish, EventType.create, EventType.deleted)
    const registryFish3 = observeAll(pond, ExampleFish, [EventType.create])
    const registryFish4 = observeAll(pond, ExampleFish, [EventType.create], [EventType.deleted])
    const registryFish5 = observeAll(
      pond,
      ExampleFish,
      event => {
        switch (event.type) {
          case EventType.create:
            return 'add'
          case EventType.deleted:
            return 'remove'
          default:
            return 'ignore';
        }
      }
    )

    Type parameters

    • P

    • E: { type: string }

    Parameters

    • pond: PondLike

      pond instance or pond.observe function

    • entityFish: FishType<unknown, E, P>

      entity to create registry fish and observe the state

    • addEventOrEventHandler: E["type"] | ReadonlyArray<E["type"]> | RegistryOnEvent<E>

      EventType or array of EventTypes to add the source.name to the registry or an eventHandler for more complex registry use-cases

    • Default value removeEvent: E["type"] | ReadonlyArray<E["type"]> = []

      EventType or array of EventTypes, when the source.name should be removed from the registry

    Returns Observable<ReadonlyArray<P>>

Const observeRegistry

  • observeRegistry<P>(pond: PondLike, registryFish: FishType<unknown, unknown, ReadonlyArray<FishName>>, entityFish: FishType<unknown, unknown, P>): Observable<ReadonlyArray<P>>
  • observeRegistry can be used to map the state of an registryFish to the entity fish

    see

    observeRegistryMap map the registry fish state to a FishName[]

    Type parameters

    • P

    Parameters

    • pond: PondLike

      pond instance or pond.observe function

    • registryFish: FishType<unknown, unknown, ReadonlyArray<FishName>>

      registry fish which state is a FishName[]

    • entityFish: FishType<unknown, unknown, P>

      entity fish to observe the state

    Returns Observable<ReadonlyArray<P>>

Const observeRegistryMap

  • observeRegistryMap<R, P>(pond: PondLike, registryFish: FishType<unknown, unknown, R>, map: (state: R) => ReadonlyArray<FishName>, entityFish: FishType<unknown, unknown, P>): Observable<ReadonlyArray<P>>
  • observeRegistryMap can be used to map the state of an registryFish to the entity fish

    The Map version take an map function to map the PublicRegistryFishState to a FishName array

    see

    observeRegistry if you don't have to map the state

    Type parameters

    • R

    • P

    Parameters

    • pond: PondLike

      pond like instance or pond.observe function

    • registryFish: FishType<unknown, unknown, R>

      registry fish that contains a array of FishNames to observe them

    • map: (state: R) => ReadonlyArray<FishName>

      map function that have to return a array on FishNames

        • (state: R): ReadonlyArray<FishName>
        • Parameters

          • state: R

          Returns ReadonlyArray<FishName>

    • entityFish: FishType<unknown, unknown, P>

      entity fish to observe the state

    Returns Observable<ReadonlyArray<P>>

Legend

Generated using TypeDoc