Skip to content

Commit

Permalink
feat: frontend Model extender (#3646)
Browse files Browse the repository at this point in the history
* feat: reintroduce frontend extenders
* chore: used `Routes` extender in bundled extensions
* chore: used `PostTypes` extender in bundled extensions
* chore: `yarn format`
* feat: `Model` frontend extender
* chore: naming
* chore(review): attributes can be nullable or undefined
* chore(review): delay extender implementation
* chore(review): unnecessary check
* chore(review): stay consistent
* chore: merge conflicts
* chore: unused import
* chore: multiline extenders
* feat: add Store extender

Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
  • Loading branch information
SychO9 authored Feb 8, 2023
1 parent 907dd70 commit e56abc1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
7 changes: 7 additions & 0 deletions js/src/forum/extend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Extend from 'flarum/common/extenders';
import User from 'flarum/common/models/User';

export default [
new Extend.Model(User) //
.attribute<boolean>('canEditNickname'),
];
6 changes: 2 additions & 4 deletions js/src/forum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import Button from 'flarum/common/components/Button';
import EditUserModal from 'flarum/common/components/EditUserModal';
import SignUpModal from 'flarum/forum/components/SignUpModal';
import SettingsPage from 'flarum/forum/components/SettingsPage';
import Model from 'flarum/common/Model';
import User from 'flarum/common/models/User';
import extractText from 'flarum/common/utils/extractText';
import Stream from 'flarum/common/utils/Stream';
import NickNameModal from './components/NicknameModal';

app.initializers.add('flarum/nicknames', () => {
User.prototype.canEditNickname = Model.attribute('canEditNickname');
export { default as extend } from './extend';

app.initializers.add('flarum/nicknames', () => {
extend(SettingsPage.prototype, 'accountItems', function (items) {
if (app.forum.attribute('displayNameDriver') !== 'nickname') return;

Expand Down
20 changes: 20 additions & 0 deletions js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// Use Flarum's tsconfig as a starting point
"extends": "flarum-tsconfig",
// This will match all .ts, .tsx, .d.ts, .js, .jsx files in your `src` folder
// and also tells your Typescript server to read core's global typings for
// access to `dayjs` and `$` in the global namespace.
"include": ["src/**/*", "../../../framework/core/js/dist-typings/@types/**/*", "@types/**/*"],
"compilerOptions": {
// This will output typings to `dist-typings`
"declarationDir": "./dist-typings",
"paths": {
"flarum/*": ["../../../framework/core/js/dist-typings/*"],
// TODO: remove after export registry system implemented
// Without this, the old-style `@flarum/core` import is resolved to
// source code in flarum/core instead of the dist typings.
// This causes an inaccurate "duplicate export" error.
"@flarum/core/*": ["../../../framework/core/js/dist-typings/*"],
}
}
}

0 comments on commit e56abc1

Please sign in to comment.