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

SharedTree: ChangeEncoder.decodeChange() should use 'Jsonable<T>' #11558

Closed
wants to merge 3 commits into from

Conversation

DLehenbauer
Copy link
Contributor

The 'Jsonable' is another helper type that can catch some attempts to JSON serialize non-JSON serializable types.

It's typically used with type inference as follows:

function foo<T>(bar: Jsonable<T>) { ... }

foo(() => "not jsonable");    // Produces a compile time error.

See 'packages/runtime/datastore-definitions/src/jsonable.ts' for details.

@DLehenbauer DLehenbauer requested review from a team as code owners August 16, 2022 18:35
@github-actions github-actions bot added area: contributor experience area: dds Issues related to distributed data structures base: main PRs targeted against main branch labels Aug 16, 2022
@@ -4,9 +4,11 @@
*/

import { bufferToString, IsoBuffer } from "@fluidframework/common-utils";
import { Jsonable } from "@fluidframework/datastore-definitions";

export abstract class ChangeEncoder<TChange> {
public abstract encodeForJson(formatVersion: number, change: TChange): JsonCompatible;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious about naming asymmetry between 'encodeForJson' and 'decodeJson'. Was that intentional?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CraigMacomber actually wrote this file and picked these names, but the names seem fairly clear to me. I wouldn't object to something like encodeAsJsonable and decodeFromJsonable.

@DLehenbauer
Copy link
Contributor Author

@alex-pardes - Motivation for PR is to pass on knowledge of Jsonable, which isn't easily discoverable.

Comment on lines 9 to 10
export abstract class ChangeEncoder<TChange> {
public abstract encodeForJson(formatVersion: number, change: TChange): JsonCompatible;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR would be much more valuable if we can delete JsonCompatible by doing something like this:

Suggested change
export abstract class ChangeEncoder<TChange> {
public abstract encodeForJson(formatVersion: number, change: TChange): JsonCompatible;
export abstract class ChangeEncoder<TChange, Jsonable<TEncoded>> {
public abstract encodeForJson(formatVersion: number, change: TChange): TEncoded;

@@ -4,9 +4,11 @@
*/

import { bufferToString, IsoBuffer } from "@fluidframework/common-utils";
import { Jsonable } from "@fluidframework/datastore-definitions";

export abstract class ChangeEncoder<TChange> {
public abstract encodeForJson(formatVersion: number, change: TChange): JsonCompatible;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CraigMacomber actually wrote this file and picked these names, but the names seem fairly clear to me. I wouldn't object to something like encodeAsJsonable and decodeFromJsonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: contributor experience area: dds Issues related to distributed data structures base: main PRs targeted against main branch status: no recent activity status: stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants