flarum / issue-archive

0 stars 0 forks source link

Rewrite Controls utils objects #175

Open w-4 opened 3 years ago

w-4 commented 3 years ago

Feature Request

Here's a screenshot of the before (left) and after: image

The biggest benefit is that when calling the function one doesn't have to use .call(discussion) anymore and the code becomes more readable. Another benefit is that you can call one utils function from another in the same file, which was previously impractical, since this was already bound to the discussion.

Applies to PostControls, DiscussionControls, UserControls. Can be done probably when converting these files to TypeScript.

dsevillamartin commented 3 years ago

Can be done probably when converting these files to TypeScript.

Not entirely sure, but I think some of these actions are referenced from other files. The import statement would change and thus would be a breaking change.

Because right now we have the import UserControls from '...', that'd have to be changed to import * as UserControls from '...' I think.

I do agree that we don't want to bind this.

askvortsov1 commented 3 years ago

My biggest concern with this approach is that the extend and override utils wouldn't work on standalone functions.

w-4 commented 3 years ago

That's true, we'd need to also export it as an object in addition. That's also needed for the extensions public API, so that webpack uglify does not alter the names.

export default DiscussionControls = {
  userControls,
  moderationControls,
  destructiveControls,
  ...
};
dsevillamartin commented 3 years ago

It doesn't matter what uglify does, as the "public API" comes from the compat files, where we use strings and so they aren't affected by uglify. Extensibility is an issue that could maybe be solved with that method, however.

askvortsov1 commented 3 years ago

We should also consider some of the options discussed in https://github.com/flarum/core/issues/1317

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We do this to keep the amount of open issues to a manageable minimum. In any case, thanks for taking an interest in this software and contributing by opening the issue in the first place!