Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Conversation

@yeze322
Copy link
Contributor

@yeze322 yeze322 commented Oct 24, 2019

Description

Previous implementation is a hack, replace it with a recommended solution.

Changes:

  1. Inside Visual Editor, hoist several related states to global store by migrating to useReducer hook
  2. In ShellApi level, register a new API syncEditorState to enable state synchronization between Shell & Visual Editor
  3. Inside Shell, consume a new computed state visualEditorActive (computed from editorState) to control if toolbar buttons (Copy/Cut/Delete) should be active.
  4. Fix a bug: selected was passed as focusedSteps but it's actually a trigger (Form, Shell)

Following works:
Apply this pattern to clipboard action, will potentialy persist copied actions in shell layer to enable copy/paste across dialog files.

Todos:

  1. [Visual Editor] reducer could be covered by UT
  2. [Visual Editor] need to clean old local context / states

Task Item

#1170 - Resolve item 1

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code refactor (non-breaking change which improve code quality, clean up, add tests, etc)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Doc update (document update)

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have functionally tested my change

Screenshots

Please include screenshots or gifs if your PR include UX changes.

@yeze322 yeze322 changed the title Hoist visual editor selection state to shell layer [WIP] Hoist visual editor selection state to shell layer Oct 25, 2019
@yeze322
Copy link
Contributor Author

yeze322 commented Oct 25, 2019

WIP: add UT for reducer

apiClient.registerApi('onFocusEvent', focusEvent);
apiClient.registerApi('onFocusSteps', focusSteps);
apiClient.registerApi('onSelect', onSelect);
apiClient.registerApi('syncEditorState', syncEditorState);
Copy link
Member

Choose a reason for hiding this comment

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

Why is this called syncEditorState? We shouldn't be "syncing" anything, that suggested were mirroring state. The Shell data should hydrate the visual editor.

Copy link
Contributor Author

@yeze322 yeze322 Oct 25, 2019

Choose a reason for hiding this comment

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

Maybe its name should be onStateChange or onStoreChange: on each state change, notify container.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a tricky problem here. Because of the iframe layer breaks change detection, state exchanging between Shell and editors has a really high cost (which resulted us to optimize it in #1106 ), so the normal pattern value + onChange no longer works fine. If we split 3 props into 3 pairs of 'value + onChange' to hydrate with Shell data, it will cause performance issue. Therefore, there is a onStateChange API for handling all state exchangings.

Copy link
Contributor Author

@yeze322 yeze322 Oct 25, 2019

Choose a reason for hiding this comment

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

According to comments below, we don't need the syncEditorState api. The interface will be:

<VisualEditor ... selection={selection} onChangeSelection={(selection) => shellApi.onChangeSelection(selection)} />

My only concern here is during a drag selection, the performance will be poor

return state;
};

const updateVisualEditorState: ReducerFunc = (state, { editorState }) => {
Copy link
Member

Choose a reason for hiding this comment

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

I don't like how you've defined this to suggest that a grouping of nodes is a concern of the visual editor. This isn't the case. The visual editor has a mechanism to group nodes and nothing more.

Here is why: If the visual editor gets redrawn for whatever reason, we still want to hold the grouped nodes in state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, This logic is supposed to be moved into lower level, at least down to ExtensionContainer / VisualEditorContainer.

Copy link
Contributor Author

@yeze322 yeze322 Oct 25, 2019

Choose a reason for hiding this comment

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

What about this one

<VisualEditor clipboardActions={actions} setClipboardActions={(actions) => shellApi.setClipboardActions(actions)} />

@yeze322
Copy link
Contributor Author

yeze322 commented Oct 25, 2019

@cwhitten I realized the issue you talked about. My following plan:

  1. revert to the 'selectTo' api and compute the boolean in design page (a simple function should work)
  2. add one more api 'setClipboard', pass clipboardActions as props

@yeze322
Copy link
Contributor Author

yeze322 commented Oct 28, 2019

Fix it in another approach, close this PR.

@yeze322 yeze322 closed this Oct 28, 2019
@cwhitten cwhitten deleted the zeye/selection-state branch March 6, 2020 00:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants