appflowy-editor icon indicating copy to clipboard operation
appflowy-editor copied to clipboard

[FR] EditorState could be listenable

Open galacticgibbon opened this issue 1 year ago • 1 comments

Description

Right now, you have to use setState to force an update when making a change to EditorState.

It would be better if you could listen to EditorState and react to changes. EditorState could extend ChangeNotifier.

Impact

It would be more intuitive and act more like common Flutter APIs like TextEditingController

Additional Context

I use flutter_hooks for ephemeral state management, so it's not straightforward to force update state with setstate like is achieved here:

      return MobileToolbarItemMenuBtn(
        icon: AFMobileIcon(
          afMobileIcons: currentDecoration.icon,
          color: MobileToolbarTheme.of(context).iconColor,
        ),
        label: Text(currentDecoration.label),
        isSelected: isSelected,
        onPressed: () {
          setState(() {
            widget.editorState.toggleAttribute(currentDecoration.name);
          });
        },
      );

galacticgibbon avatar Jan 01 '24 14:01 galacticgibbon

I can't see a reason why you couldn't use eg. the Selection or Attribute toggle Notifiers for your use-case.

editorState.toggledStyleNotifier;
editorState.selectionNotifier;

You can also subscribe to the transactions applied to the EditorState through editorState.transactionStream.

Are there any cases we have missed or you think would require more coverage?

Xazin avatar Jan 01 '24 15:01 Xazin