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

Change insertion markers to use JSON deserialization when duplicating blocks #7316

Closed
1 task done
BeksOmega opened this issue Jul 21, 2023 · 5 comments · Fixed by #7364 or #7730
Closed
1 task done

Change insertion markers to use JSON deserialization when duplicating blocks #7316

BeksOmega opened this issue Jul 21, 2023 · 5 comments · Fixed by #7364 or #7730
Assignees
Labels
issue: feature request Describes a new feature and why it should be added size: small Bugs that can be picked up and completed in 1-3 days

Comments

@BeksOmega
Copy link
Collaborator

Check for duplicates

  • I have searched for similar issues before opening a new one.

Problem

Insertion markers duplicate the block being dragged, and then tell the duplicate to be an insertion marker.

Currently the duplication duplicates (ha) a lot of code from the serialization system. We think this is because in the past the XML system didn't have a good way to just serialize and deserialize a single block (without children). But the JSON system does have this!

Request

Change the insertion marker createMarkerBlock code over to use JSON serialization and deserialization.

Alternatives considered

No response

Additional context

Sparked by this discussion: https://groups.google.com/g/blockly/c/gcvynl88QLY/m/shFyX4x0BwAJ

@BeksOmega BeksOmega added issue: feature request Describes a new feature and why it should be added issue: triage Issues awaiting triage by a Blockly team member labels Jul 21, 2023
@maribethb maribethb added this to the Upcoming milestone Jul 26, 2023
@maribethb maribethb added size: small Bugs that can be picked up and completed in 1-3 days and removed issue: triage Issues awaiting triage by a Blockly team member labels Jul 26, 2023
@varshneydevansh
Copy link
Contributor

varshneydevansh commented Aug 4, 2023

Can I pick this challenge?

@BeksOmega
Copy link
Collaborator Author

Sure go for it @varshneydevansh !

@varshneydevansh
Copy link
Contributor

varshneydevansh commented Aug 5, 2023

I found the discussion to be very intriguing and understood how we arrived at this issue.

To use the JSON serialization and deserialization the toJSON method is used to serialize the sourceBlock into a JSON object, which captures the relevant data of the block. The fromJson method is then called on the result block to deserialize the JSON and populate the block with the serialized data.

Is this is a suitable approach?


I think I also have to remove all the related functions regarding the mutation state. for example-

saveExtraState?: () => AnyDuringMigration;


If I do this, then I also have to remove the references from these places? Or should I leave them as it's and just change the createMarkerBlock

image

I think I also have to add the toJson and fromJson something like this in -

export class BlockSvg

export class BlockSVG {
    // Add the toJson method
    toJson(): string {
        return JSON.stringify(this);
    }

    // Add the fromJson method
    fromJson(json: string): void {
        const data = JSON(json);

@BeksOmega
Copy link
Collaborator Author

Hello @varshneydevansh =)

When I said the "JSON serialization system" above I meant this one! The example of serializing individual blocks should help you.

So you don't need to remove or add any APIs, just call the APIs linked above from the insertion marker code to create the marker block =)

I hope that helps! If you have any further questions please reply =)

@BeksOmega
Copy link
Collaborator Author

BeksOmega commented Sep 7, 2023

Reoppening due to rollback #7430

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: feature request Describes a new feature and why it should be added size: small Bugs that can be picked up and completed in 1-3 days
Projects
None yet
3 participants