mirror of
https://github.com/flarum/core.git
synced 2025-07-10 11:26:24 +02:00
fix: breaking change in Search component - renaming of state
property (#3212)
* fix: breaking change in search component's public api * fix: add setter * feat: add deprecation warning helper This reduces bundle size as a result of deprecation warning in our JS, as well as maintaining a consistent format across warnings. * feat: fire deprecation warning on usage of `Search.state` * chore: use consistent deprecation warning across core * fix: `/pull` not `/issue` * chore: format
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
import app from '../common/app';
|
import app from '../common/app';
|
||||||
import { FlarumRequestOptions } from './Application';
|
import { FlarumRequestOptions } from './Application';
|
||||||
import fireDebugWarning from './helpers/fireDebugWarning';
|
import { fireDeprecationWarning } from './helpers/fireDebugWarning';
|
||||||
import Model, { ModelData, SavedModelData } from './Model';
|
import Model, { ModelData, SavedModelData } from './Model';
|
||||||
|
|
||||||
export interface MetaInformation {
|
export interface MetaInformation {
|
||||||
@ -123,11 +123,7 @@ export default class Store {
|
|||||||
if (!this.models[data.type]) {
|
if (!this.models[data.type]) {
|
||||||
if (!allowUnregistered) {
|
if (!allowUnregistered) {
|
||||||
setTimeout(() =>
|
setTimeout(() =>
|
||||||
fireDebugWarning(
|
fireDeprecationWarning(`Pushing object of type \`${data.type}\` not allowed, as type not yet registered in the store.`, '3206')
|
||||||
`[Flarum 2.0 Deprecation] Cannot push object of type \`${data.type}\`, as that type has not yet been registered in the store. This will throw an error in Flarum 2.0 and later.
|
|
||||||
|
|
||||||
For more information, see https://github.com/flarum/core/pull/3206.`
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,3 +16,21 @@ export default function fireDebugWarning(...args: Parameters<typeof console.warn
|
|||||||
|
|
||||||
console.warn(...args);
|
console.warn(...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fire a Flarum deprecation warning which is shown in the JS console.
|
||||||
|
*
|
||||||
|
* These warnings are only shown when the forum is in debug mode, and the function exists to
|
||||||
|
* reduce bundle size caused by multiple warnings across our JavaScript.
|
||||||
|
*
|
||||||
|
* @param message The message to display. (Short, but sweet, please!)
|
||||||
|
* @param githubId The PR or Issue ID with more info in relation to this change.
|
||||||
|
* @param [removedFrom] The version in which this feature will be completely removed. (default: 2.0)
|
||||||
|
* @param [repo] The repo which the issue or PR is located in. (default: flarum/core)
|
||||||
|
*
|
||||||
|
* @see {@link fireDebugWarning}
|
||||||
|
*/
|
||||||
|
export function fireDeprecationWarning(message: string, githubId: string, removedFrom: string = '2.0', repo: string = 'flarum/core'): void {
|
||||||
|
// GitHub auto-redirects between `/pull` and `/issues` for us, so using `/pull` saves 2 bytes!
|
||||||
|
fireDebugWarning(`[Flarum ${removedFrom} Deprecation] ${message}\n\nSee: https://github.com/${repo}/pull/${githubId}`);
|
||||||
|
}
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
|
import { fireDeprecationWarning } from '../helpers/fireDebugWarning';
|
||||||
|
|
||||||
|
const deprecatedNotice = 'The `evented` util is deprecated and no longer supported.';
|
||||||
|
const deprecationIssueId = '2547';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `evented` mixin provides methods allowing an object to trigger events,
|
* The `evented` mixin provides methods allowing an object to trigger events,
|
||||||
* running externally registered event handlers.
|
* running externally registered event handlers.
|
||||||
*
|
*
|
||||||
* @deprecated v1.2, to be removed in v2.0
|
* @deprecated v1.2, to be removed in v2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import fireDebugWarning from '../helpers/fireDebugWarning';
|
|
||||||
|
|
||||||
const deprecatedNotice =
|
|
||||||
'The `evented` util is deprecated and will be removed in Flarum 2.0. For more info, please see https://github.com/flarum/core/issues/2547';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
/**
|
/**
|
||||||
* Arrays of registered event handlers, grouped by the event name.
|
* Arrays of registered event handlers, grouped by the event name.
|
||||||
@ -27,7 +26,7 @@ export default {
|
|||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
getHandlers(event) {
|
getHandlers(event) {
|
||||||
fireDebugWarning(deprecatedNotice);
|
fireDeprecationWarning(deprecatedNotice, deprecationIssueId);
|
||||||
|
|
||||||
this.handlers = this.handlers || {};
|
this.handlers = this.handlers || {};
|
||||||
|
|
||||||
@ -44,7 +43,7 @@ export default {
|
|||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
trigger(event, ...args) {
|
trigger(event, ...args) {
|
||||||
fireDebugWarning(deprecatedNotice);
|
fireDeprecationWarning(deprecatedNotice, deprecationIssueId);
|
||||||
|
|
||||||
this.getHandlers(event).forEach((handler) => handler.apply(this, args));
|
this.getHandlers(event).forEach((handler) => handler.apply(this, args));
|
||||||
},
|
},
|
||||||
@ -56,7 +55,7 @@ export default {
|
|||||||
* @param {function} handler The function to handle the event.
|
* @param {function} handler The function to handle the event.
|
||||||
*/
|
*/
|
||||||
on(event, handler) {
|
on(event, handler) {
|
||||||
fireDebugWarning(deprecatedNotice);
|
fireDeprecationWarning(deprecatedNotice, deprecationIssueId);
|
||||||
|
|
||||||
this.getHandlers(event).push(handler);
|
this.getHandlers(event).push(handler);
|
||||||
},
|
},
|
||||||
@ -69,7 +68,7 @@ export default {
|
|||||||
* @param {function} handler The function to handle the event.
|
* @param {function} handler The function to handle the event.
|
||||||
*/
|
*/
|
||||||
one(event, handler) {
|
one(event, handler) {
|
||||||
fireDebugWarning(deprecatedNotice);
|
fireDeprecationWarning(deprecatedNotice, deprecationIssueId);
|
||||||
|
|
||||||
const wrapper = function () {
|
const wrapper = function () {
|
||||||
handler.apply(this, arguments);
|
handler.apply(this, arguments);
|
||||||
@ -87,7 +86,7 @@ export default {
|
|||||||
* @param {function} handler The function that handles the event.
|
* @param {function} handler The function that handles the event.
|
||||||
*/
|
*/
|
||||||
off(event, handler) {
|
off(event, handler) {
|
||||||
fireDebugWarning(deprecatedNotice);
|
fireDeprecationWarning(deprecatedNotice, deprecationIssueId);
|
||||||
|
|
||||||
const handlers = this.getHandlers(event);
|
const handlers = this.getHandlers(event);
|
||||||
const index = handlers.indexOf(handler);
|
const index = handlers.indexOf(handler);
|
||||||
|
@ -9,8 +9,8 @@ import icon from '../../common/helpers/icon';
|
|||||||
import SearchState from '../states/SearchState';
|
import SearchState from '../states/SearchState';
|
||||||
import DiscussionsSearchSource from './DiscussionsSearchSource';
|
import DiscussionsSearchSource from './DiscussionsSearchSource';
|
||||||
import UsersSearchSource from './UsersSearchSource';
|
import UsersSearchSource from './UsersSearchSource';
|
||||||
|
import { fireDeprecationWarning } from '../../common/helpers/fireDebugWarning';
|
||||||
import type Mithril from 'mithril';
|
import type Mithril from 'mithril';
|
||||||
import Model from '../../common/Model';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `SearchSource` interface defines a section of search results in the
|
* The `SearchSource` interface defines a section of search results in the
|
||||||
@ -53,14 +53,33 @@ export interface SearchAttrs extends ComponentAttrs {
|
|||||||
*
|
*
|
||||||
* - state: SearchState instance.
|
* - state: SearchState instance.
|
||||||
*/
|
*/
|
||||||
export default class Search<T extends SearchAttrs = SearchAttrs> extends Component<T> {
|
export default class Search<T extends SearchAttrs = SearchAttrs> extends Component<T, SearchState> {
|
||||||
/**
|
/**
|
||||||
* The minimum query length before sources are searched.
|
* The minimum query length before sources are searched.
|
||||||
*/
|
*/
|
||||||
protected static MIN_SEARCH_LEN = 3;
|
protected static MIN_SEARCH_LEN = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The instance of `SearchState` for this component.
|
||||||
|
*/
|
||||||
protected searchState!: SearchState;
|
protected searchState!: SearchState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The instance of `SearchState` for this component.
|
||||||
|
*
|
||||||
|
* @deprecated Replace with`this.searchState` instead.
|
||||||
|
*/
|
||||||
|
// TODO: [Flarum 2.0] Remove this.
|
||||||
|
// @ts-expect-error This is a get accessor, while superclass defines this as a property. This is needed to prevent breaking changes, however.
|
||||||
|
protected get state() {
|
||||||
|
fireDeprecationWarning('`state` property of the Search component is deprecated', '3212');
|
||||||
|
return this.searchState;
|
||||||
|
}
|
||||||
|
protected set state(state: SearchState) {
|
||||||
|
fireDeprecationWarning('`state` property of the Search component is deprecated', '3212');
|
||||||
|
this.searchState = state;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the search input has focus.
|
* Whether or not the search input has focus.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user