How to use the lodash-decorators.debounce function in lodash-decorators

To help you get started, we’ve selected a few lodash-decorators examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / lodash-decorators / lodash-decorators-tests.ts View on Github external
}

const person4 = new Person4('Joe', 'Smith') as Person4Ex;

person4.logName(); // joe-smith

//
// Instance Decorators
//

class Person5 {
    @curry(2) // <= prototype decorator
    @debounce(100) // <= instance decorator
    getName() { } // => Throws an error. (╯°□°)╯︵ ┻━┻

    @debounce(100) // <= instance decorator
    @curry(2) // <= prototype decorator
    getName2() { } // => All is well :)
}

//
// Getters and Setters
//

import { once, flow } from 'lodash-decorators';

function alwaysArray(value: string | string[]): string[] {
    return Array.isArray(value) ? value : _.isUndefined(value) ? [] : [value];
}

class Person6 {
    constructor() { }
github stream-labs / streamlabs-obs / app / components / page-components / Chatbot / windows / ChatbotWordProtectionList.vue.ts View on Github external
onAddingNewItemHandler(editedItem?: IWordProtectionBlackListItem, index: number = -1) {
    if (editedItem) {
      this.newListItem = editedItem;
    }
    this.editIndex = index;
    this.$modal.show(NEW_WORD_PROTECTION_LIST_MODAL_ID);
  }

  onDeleteAliasHandler(index: number) {
    const newListItemArray = this.value.slice(0);
    newListItemArray.splice(index, 1);
    this.$emit('input', newListItemArray);
  }

  @Watch('errors.items.length')
  @debounce(200)
  async onErrorsChanged() {
    await this.$refs.form.validateAndGetErrorsCount();
  }

  async onAddNewItemHandler() {
    if (await this.$refs.form.validateAndGetErrorsCount()) return;

    const newListItemArray = this.value.slice(0);

    if (this.editIndex > -1) {
      // editing existing item
      newListItemArray.splice(this.editIndex, 1, this.newListItem);
    } else {
      newListItemArray.push(this.newListItem);
    }
    this.$emit('input', newListItemArray);
github stream-labs / streamlabs-obs / app / components / page-components / Chatbot / shared / ChatbotAliases.vue.ts View on Github external
placeholder: '!example',
  };

  get isDuplicate() {
    // remove "!" and check the rest
    const existingWithoutPrefix = this.value.map(alias => alias.replace('!', ''));
    const newWithoutPrefix = this.newAlias.replace('!', '');
    return (
      existingWithoutPrefix.length > 0 &&
      newWithoutPrefix &&
      existingWithoutPrefix.indexOf(newWithoutPrefix) > -1
    );
  }

  @Watch('newAlias', { immediate: true, deep: true })
  @debounce(1)
  onCommandChanged(value: string, oldValue: string) {
    if (oldValue) {
      this.newAlias = value.replace(/ +/g, '');
    }
  }

  onAddAliasHandler() {
    if (!this.newAlias) return;
    if (this.isDuplicate) return;

    const newAliasArray = this.value.slice(0);
    newAliasArray.push(this.formatAlias(this.newAlias));
    this.$emit('input', newAliasArray);
    this.newAlias = '';
  }
github stream-labs / streamlabs-obs / app / components / page-components / Chatbot / windows / ChatbotCustomCommandWindow.vue.ts View on Github external
if (this.isEdit) {
      this.newCommand = cloneDeep(this.customCommandToUpdate);
      this.newCommand.permission.level = this.customCommandToUpdate.permission.level;
    }
  }

  get isEdit() {
    return this.customCommandToUpdate && this.customCommandToUpdate.id;
  }

  get customCommandToUpdate() {
    return this.chatbotApiService.Common.state.customCommandToUpdate;
  }

  @Watch('newCommand', { immediate: true, deep: true })
  @debounce(1)
  onCommandChanged(value: ICustomCommand, oldValue: ICustomCommand) {
    if (oldValue) {
      this.newCommand.command = value.command.replace(/ +/g, '');
    }
  }

  // metadata
  commandMetadata: ITextMetadata = {
    required: true,
    type: EInputType.text,
    title: $t('Command'),
    placeholder: $t('Enter the text string which will trigger the response'),
    tooltip: $t('Enter a word used to trigger a response'),
    min: 2,
    max: 25,
    uuid: $t('Command'),
github stream-labs / streamlabs-obs / app / components / page-components / Chatbot / windows / ChatbotTimerWindow.vue.ts View on Github external
// if editing existing custom command
    if (this.isEdit) {
      this.newTimer = cloneDeep(this.timerToUpdate);
    }
  }

  get isEdit() {
    return this.timerToUpdate && this.timerToUpdate.id;
  }

  get timerToUpdate() {
    return this.chatbotApiService.Common.state.timerToUpdate;
  }

  @Watch('newTimer', { immediate: true, deep: true })
  @debounce(1)
  onCommandChanged(value: IChatbotTimer, oldValue: IChatbotTimer) {
    if (oldValue) {
      this.newTimer.name = value.name.replace(/ +/g, '');
      this.newTimer.message = value.message.replace(/(\r\n|\r|\n)/g, '');
    }
  }

  @Watch('errors.items.length')
  @debounce(200)
  async onErrorsChanged() {
    await this.$refs.form.validateAndGetErrorsCount();
  }

  async onSaveHandler() {
    if (await this.$refs.form.validateAndGetErrorsCount()) return;
github lskjs / ux / packages / dashboard / UI / organisms / TreeInput / TreeInput.jsx View on Github external
@observer
class TreeInput extends Component {
  constructor(props) {
    super(props);
    this.state = {
      value: props.value || [],
    };
  }

  componentWillReceiveProps({ value }) {
    this.setState({
      value: value || [],
    });
  }

  @debounce(50)
  handleChangeDebounced() {
    // console.log('handleChangeDebounced');
    const { onChange } = this.props;
    if (onChange) onChange(this.state.value);
  }

  @autobind
  handleSetStateWithDebouncedCallback(value) {
    this.setState({ value: uniq(value) }, () => {
      this.handleChangeDebounced();
    });
  }

  @autobind
  handleCheck(value) {
    const { flat = false } = this.props;
github lskjs / ux / packages / dashboard / UI / molecules / TreeInput / TreeInput.jsx View on Github external
@observer
class TreeInput extends Component {
  constructor(props) {
    super(props);
    this.state = {
      value: props.value || [],
    };
  }

  componentWillReceiveProps({ value }) {
    this.setState({
      value: value || [],
    });
  }

  @debounce(50)
  handleChangeDebounced() {
    // console.log('handleChangeDebounced');
    const { onChange } = this.props;
    if (onChange) onChange(this.state.value);
  }

  @autobind
  handleChange(value) {
    const { flat = false } = this.props;
    // чистим от категорий игр
    if (!flat) {
      value = value.filter(id => id.charAt(0) !== '@');
    }
    value = uniq(value);

    // console.log('handleChange');
github stream-labs / streamlabs-obs / app / components / page-components / Chatbot / windows / ChatbotQueuePreferencesWindow.vue.ts View on Github external
max: 450,
      },
    };
  }

  get queuePreferences() {
    return this.chatbotApiService.Queue.state.queuePreferencesResponse;
  }

  mounted() {
    // if editing existing custom command
    this.generalSettings = cloneDeep(this.queuePreferences.settings.general);
  }

  @Watch('errors.items.length')
  @debounce(200)
  async onErrorsChanged() {
    await this.$refs.form.validateAndGetErrorsCount();
  }

  onSaveHandler() {
    const newPreferences = cloneDeep(this.queuePreferences);
    newPreferences.settings.general = this.generalSettings;
    this.chatbotApiService.Queue.updateQueuePreferences(newPreferences);
  }
}
github lskjs / ux / src / UI / molecules / InputArray / InputArray.jsx View on Github external
};
  }

  //
  componentWillReceiveProps(nextProps) {
    if (nextProps.value !== this.props.value) {
      // Perform some operation
      this.setState({ value: nextProps.value });
    }
  }

  shouldComponentUpdate(nextProps, nextState) {
    return !isEqual(nextProps.value, this.props.value) || !isEqual(nextState.value, this.state.value);
  }

  @debounce(100)
  onChangeDebounced() {
    this.onChange();
  }

  @autobind
  onChange() {
    const { value } = this.state;
    if (this.props.onChange) this.props.onChange((value || []).filter(a => a));
  }

  @autobind
  onChangeHandler(i, val) {
    const value = [...this.state.value];
    value[i] = val;

    this.setState({
github lskjs / ux / packages / dashboard / UI / molecules / InputArray / InputArray.jsx View on Github external
};
  }

  //
  componentWillReceiveProps(nextProps) {
    if (nextProps.value !== this.props.value) {
      // Perform some operation
      this.setState({ value: nextProps.value });
    }
  }

  shouldComponentUpdate(nextProps, nextState) {
    return !isEqual(nextProps.value, this.props.value) || !isEqual(nextState.value, this.state.value);
  }

  @debounce(100)
  onChangeDebounced() {
    this.onChange();
  }

  @autobind
  onChange() {
    const { value } = this.state;
    if (this.props.onChange) this.props.onChange((value || []).filter(a => a));
  }

  @autobind
  onChangeHandler(i, val) {
    const value = [...this.state.value];
    value[i] = val;

    this.setState({

lodash-decorators

A collection of decorators using lodash at it's core.

MIT
Latest version published 6 years ago

Package Health Score

53 / 100
Full package analysis

Popular lodash-decorators functions