Accessing a view's state without knowing if it's EditorView or MenuBarEditorView (or other)

I need a way to write a function that accepts a view and access it’s state without knowing if it’s EditorView or MenuBarEditorView (or other)

for example:

function f(view, tr) {
  let state= view.???
  let newState=state.apply(tr);

How can this be done ? can we have a state atrribute on view or a getState() method ?

What if you just change the callers of your function to pass menuView.editor when they know that the value they have is a MenuBarEditorView? I’m not really interested in making that class mimic regular EditorView's interface, since the latter has a lot of properties and methods that we’d end up needing to forward.

Yes I can do that or I can pass a getState() function but it seems awkward.

I am trying to understand why there is no View interface that EditorView and MenuBarEditorView etc need to implement that include the state ?

If I understand correctly, every kind of view has an EditorState, an updateState function, a dispatch function etc so that sounds like a natural place to create an interface that views need to implement.

Yes MenuBarEditorView will need to forward them from it’s editor but that’s an internal details of MenuBarEditorView implementation, and will make using it much more natural.