springload / wagtaildraftail

🐦📝🍸 Draft.js editor for Wagtail, built upon Draftail and draftjs_exporter
https://pypi.python.org/pypi/wagtaildraftail
MIT License
24 stars 3 forks source link

Stop defining boilerplate entity strategy #6

Closed thibaudcolas closed 7 years ago

thibaudcolas commented 7 years ago

The two current decorators define the following boilerplate as their strategy:

export function findDocumentEntities(contentBlock, callback) {
  contentBlock.findEntityRanges((character) => {
    const entityKey = character.getEntity();
    return entityKey !== null && Entity.get(entityKey).getType() === ENTITY_TYPE.DOCUMENT;
  }, callback);
}

This is boilerplate-y enough that it should be the default behavior of Draftail – if no custom strategy is defined, use the following code with the entity's type. Note that this has to be implemented in Draftail first, then used in here. Would also save us from having to write complex tests of this behavior here.