@atlaskit/mention
Version:
A React component used to display user profiles in a list for 'Mention' functionality
28 lines • 1.56 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import { padArray } from '../util';
/**
* This component is stateful and should be instantianted per contextIdentifiers.
*/
export default class ContextMentionResource {
constructor(mentionProvider, contextIdentifier) {
_defineProperty(this, "callWithContextIds", (f, declaredArgs) => (...args) => {
const argsLength = args ? args.length : 0;
// cover the scenario where optional parameters are not passed
// by passing undefined instead to keep the contextIdentifiers parameter in the right position
const mentionArgs = argsLength !== declaredArgs ? padArray(args, declaredArgs - argsLength, undefined) : args;
return this.mentionProvider[f](...mentionArgs, this.contextIdentifier);
});
_defineProperty(this, "callDefault", f => (...args) => this.mentionProvider[f](...args));
_defineProperty(this, "subscribe", this.callDefault('subscribe'));
_defineProperty(this, "unsubscribe", this.callDefault('unsubscribe'));
_defineProperty(this, "filter", this.callWithContextIds('filter', 1));
_defineProperty(this, "recordMentionSelection", this.callWithContextIds('recordMentionSelection', 1));
_defineProperty(this, "shouldHighlightMention", this.callDefault('shouldHighlightMention'));
_defineProperty(this, "isFiltering", this.callDefault('isFiltering'));
this.mentionProvider = mentionProvider;
this.contextIdentifier = contextIdentifier;
}
getContextIdentifier() {
return this.contextIdentifier;
}
}