Want to keep track of and work with all fish of a specific type? Meet the RegistryFish pattern.
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
Registry toolkit is available as an npm package.
npm install @actyx-contrib/registry
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
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 |
private and public state of the registry fish
OnEventHandler for a registry fish
'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 changeconst eventHandler: RegistryOnEvent<Event> = event => {
switch (event.type) {
case EventType.create:
return 'add'
case EventType.deleted:
return 'remove'
default:
return 'ignore';
}
}
Create a Registry fish for a given fish type
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';
}
}
)
Fish to create the registry for
EventType or array of EventTypes to add the source.name to the registry or an eventHandler for more complex registry use-cases
EventType or array of EventTypes, when the source.name should be removed from the registry
create an internal registry fish and return a stream of the state of all referenced entryFish as array
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';
}
}
)
pond instance or pond.observe function
entity to create registry fish and observe the state
EventType or array of EventTypes to add the source.name to the registry or an eventHandler for more complex registry use-cases
EventType or array of EventTypes, when the source.name should be removed from the registry
observeRegistry can be used to map the state of an registryFish to the entity fish
pond instance or pond.observe function
registry fish which state is a FishName[]
entity fish to observe the state
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
pond like instance or pond.observe function
registry fish that contains a array of FishName
s to observe them
map function that have to return a array on FishName
s
entity fish to observe the state
Generated using TypeDoc
type to use the pondLike or the observe function it self