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

Make actions serializable #591

Closed
andrevmatos opened this issue Nov 25, 2019 · 2 comments · Fixed by #759
Closed

Make actions serializable #591

andrevmatos opened this issue Nov 25, 2019 · 2 comments · Fixed by #759
Assignees
Labels
5 backlog Proposals or issues to be fixed in the future enhancement New feature or request refactor sdk 🖥

Comments

@andrevmatos
Copy link
Contributor

andrevmatos commented Nov 25, 2019

Description

We need serializable actions. Usually, it's not expected actions to need to be serialized, nor go in state, but it's useful for one specific usecase: pending actions that have a confirmation counterpart, and we need to be able to recover in case client is closed between both.

The action creator implementation should use io-ts, our codec/validation library of choice, and be self-contained (no multiple places of declarations to add a new action). It must also be type-safe and implement the FSA pattern (actions being plain objects containg only type, payload, meta & error properties).

From this, it'd be interesting if the Acion Creator itself was the codec instance, so members can be accessed directly, but it may not be practical to do it over the callable function needed for the action creator. If this is the case, the codec can be defined as a codec property.

It may replace or extend our typesafe-actions dependency, may have an interface similar to it (to minimize changes), but ideally replace standalone utilities (ActionType, getType, isActionOf, etc) with methods/member functions in the action creator object itself.

A generic Error serialization codec is needed for the error actions, like serialize-error but typesafe and compatible with io-ts. No need for strong guarantees on the types, as they're mostly informative in the SDK.

Acceptance criteria

  • Actions can be serialized
  • Actions can be deserialized/validated
  • Errors payloads can also be [de]serialized
  • Actions are plain objects in the FSA pattern
  • Action Creators can be created passing io-ts codecs for payload & meta members
  • The action codec can be accessed, but relevant properties/methods are exposed through utility members.
  • An efficient type-guard is exposed as a member arrow function (no this unbind) of the AC which checks only type literal instead of codec.is which validates recursively
  • Codec, payload, meta and literal type types are exposed as well; a standalone ActionType generic can also be exposed to calculate this in a standalone way
  • All our current action creators are converted to use this implementation/factory

Tasks

  • [ ]
@andrevmatos andrevmatos added enhancement New feature or request sdk 🖥 refactor backlog Proposals or issues to be fixed in the future labels Nov 25, 2019
@christianbrb
Copy link
Contributor

@nephix
Copy link
Contributor

nephix commented Nov 28, 2019

If we're working on the SDK actions it might make sense to investigate whether [email protected] would help with our requirements. We recently had a dependency PR #474 (comment) that tried to bump it to 5.x which deprecates the way we currently create our actions. Maybe 5.x makes serializing these easier or we can update nontheless if we are going to touch most of our actions anyway.

Here's the official migration and deprecation guide: https://github.com/piotrwitek/typesafe-actions#v4xx-to-v5xx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 backlog Proposals or issues to be fixed in the future enhancement New feature or request refactor sdk 🖥
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants