Editor mode vs action terminology

Editor mode vs action terminology

Loren MaxwellLoren Maxwell Posts: 485Questions: 119Answers: 10

This is admittedly trivial, but I've been meaning to mention it and I'm virtually sitting in a boring staff meeting so I thought this might be a good time :smile:

The API has mode(), which is either create, edit, or remove.

But for events, such as open, the parameters are function( e, mode, action ), where the mode is main, inline, or bubble.

The action parameter is where the create, edit, or remove are found.

There have been a couple of times I've programed an event where I've done:

editor.on('open', function (e, mode, action) {
    // Should be "action == 'edit'" but the
    // api method "mode()" has thrown me off
    if (mode == 'edit') {
        ...
    }
});

The inconsistency always makes me wonder if it wouldn't be better to use the terminology from the event fields and have an action() method that will eventually replace the mode() method?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 65,588Questions: 1Answers: 10,904 Site admin
    Answer ✓

    Hah - an excellent use for a meeting :).

    Darn, I'd hoped to avoid an inconsistency in naming like that, but yes, I can see that it would be confusing there. I'll add an action() method as you suggest and see about tidying up the event documentation.

    Thanks for flagging this up!

    Allan

  • Loren MaxwellLoren Maxwell Posts: 485Questions: 119Answers: 10
    edited January 22

    Thanks, @allan -- I haven't checked all the event documentation, but action() would make it consistent with the few I checked.

    I think another possibility that would avoid additional programming and preserve backward compatibility would be to keep mode() as is and change the parameters in the event documentation to something like:

    // Note parameters are now documented as
    // (e, method, mode) vs (e, mode, action)
    editor.on('open', function (e, method, mode) {
    
       switch(method) {
           case 'main':
           case 'inline':
           case 'bubble':
           break;
       }
    
       switch(mode) {
           case 'create':
           case 'edit':
           case 'remove':
           break;
       }
    
    });
    

    I know I can use the (e, method, mode) or whatever else for the parameter names in my own code, but I usually use the ones from the event documentation to make sure I'm reminded of and passing the correct parameters.

    Either way, I trust you'll work out a solution!

  • allanallan Posts: 65,588Questions: 1Answers: 10,904 Site admin

    I think the tweak to the naming in the documentation is the best solution for now - thank you for suggesting that. I've just committed that change (it might be a little while before it is on the site though, as I've put it in a development branch).

    I can still add an action() method if it is needed (or possibly call it method() now), but I'm not sure how much it would be used...

    Allan

  • Loren MaxwellLoren Maxwell Posts: 485Questions: 119Answers: 10

    Thanks, @allan!

    Changing the documentation seems to be the easiest and best solution!

Sign In or Register to comment.