lodash#isFunction JavaScript Examples

The following examples show how to use lodash#isFunction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.js    From hzero-front with Apache License 2.0 7 votes vote down vote up
/**
 * 获取组件的属性
 * @param {Object} field - 字段
 * @param {String} componentType - 组件类型
 * @param {Object} context - Page的this
 */
export function getComponentProps({ field = {}, componentType = 'Input', context }) {
  const propFunc = propUtils[componentType];
  if (isFunction(propFunc)) {
    return propFunc(field.props, context, field);
  } else {
    return getInputProps(field.props, context, field);
  }
}
Example #2
Source File: checkStore.js    From QiskitFlow with Apache License 2.0 6 votes vote down vote up
/**
 * Validate the shape of redux store
 */
export default function checkStore(store) {
  const shape = {
    dispatch: isFunction,
    subscribe: isFunction,
    getState: isFunction,
    replaceReducer: isFunction,
    runSaga: isFunction,
    injectedReducers: isObject,
    injectedSagas: isObject,
  };
  invariant(
    conformsTo(store, shape),
    '(app/utils...) injectors: Expected a valid redux store',
  );
}
Example #3
Source File: index.js    From Lambda with MIT License 6 votes vote down vote up
render() {
    const { node, style, onSelect, customStyles } = this.props;
    const decorators = this.decorators();
    const animations = this.animations();
    const { ...restAnimationInfo } = animations.drawer;
    return (
      <Li style={style.base}>
        <NodeHeader
          decorators={decorators}
          animations={animations}
          node={node}
          style={style}
          customStyles={customStyles}
          onClick={() => this.onClick()}
          onSelect={isFunction(onSelect) ? () => onSelect(node) : undefined}
        />
        <Drawer restAnimationInfo={{ ...restAnimationInfo }}>
          {node.toggled ? this.renderChildren(decorators, animations) : null}
        </Drawer>
      </Li>
    );
  }
Example #4
Source File: checkStore.js    From hackchat-client with Do What The F*ck You Want To Public License 6 votes vote down vote up
/**
 * Check store object integrity and emit error if invalid
 * @param store Redux store instance
 */
export default function checkStore(store) {
  const shape = {
    dispatch: isFunction,
    subscribe: isFunction,
    getState: isFunction,
    replaceReducer: isFunction,
    runSaga: isFunction,
    injectedReducers: isObject,
    injectedSagas: isObject,
  };

  invariant(
    conformsTo(store, shape),
    '(app/utils...) injectors: Expected a valid redux store',
  );
}
Example #5
Source File: Popper.jsx    From kube-design with MIT License 6 votes vote down vote up
renderContent() {
    const {
      className: propsClassName,
      type,
      always,
      style,
      content,
      showArrow,
    } = this.props;
    const { visible } = this.state;

    return (
      <div
        className={classNames("popper", propsClassName, {
          "is-active": visible || always,
        })}
        ref={(ref) => {
          this.popper = ref;
        }}
        style={style}
        onClick={this.handlePopperClick}
      >
        <div className={`${type}-content`}>
          {isFunction(content) ? content() : content}
        </div>
        {showArrow ? (
          <div
            className="popper-arrow"
            ref={(ref) => {
              this.arrow = ref;
            }}
          />
        ) : null}
      </div>
    );
  }
Example #6
Source File: index.js    From hzero-front with Apache License 2.0 6 votes vote down vote up
componentDidMount() {
    const { onRef, onGetValidateDataSourceHook, onGetDataSourceHook } = this.props;
    // 传递 this, 获取表单数据的方法, 校验并获取表单数据的方法 传递出去
    if (isFunction(onRef)) {
      onRef(this);
    }
    if (isFunction(onGetValidateDataSourceHook)) {
      onGetValidateDataSourceHook(this.getValidateDataSource);
    }
    if (isFunction(onGetDataSourceHook)) {
      onGetDataSourceHook(this.getDataSource);
    }
  }
Example #7
Source File: sagaInjectors.js    From rysolv with GNU Affero General Public License v3.0 6 votes vote down vote up
checkDescriptor = descriptor => {
  const shape = {
    saga: isFunction,
    mode: mode => isString(mode) && allowedModes.includes(mode),
  };
  invariant(
    conformsTo(descriptor, shape),
    '(app/utils...) injectSaga: Expected a valid saga descriptor',
  );
}
Example #8
Source File: use-combobox.js    From awesome-react-starter with MIT License 6 votes vote down vote up
useCombobox = ({ items, onSelect, defaultSelected }) => {
  const [inputItems, setInputItems] = useState(items);

  const downshift = useDownshift({
    items: inputItems,
    itemToString: (item) => item?.label || item,
    defaultSelectedItem: items.find((item) => item?.value === defaultSelected) || null,
    onInputValueChange: ({ inputValue }) => {
      setInputItems(
        items.filter((item) => item.label.toLowerCase().includes(inputValue.toLowerCase()))
      );
    },
    onSelectedItemChange: ({ selectedItem }) => {
      if (isFunction(onSelect)) {
        return onSelect(selectedItem?.value);
      }
    },
  });

  return {
    inputItems,
    ...downshift,
  };
}
Example #9
Source File: change-value.js    From jafar with MIT License 6 votes vote down vote up
verifyValidValue = (fieldId, model, value, resolve) => {
  if (isFunction(value) && !model.fields[fieldId].component) {
    const ERROR_PREFIX = 'changeValue -';
    const error = createError(ERROR_PREFIX, errors.CHANGE_VALUE_UPDATER_NOT_SUPPORTED, { model, fieldId }, []);
    log.error(error);
    resolve();
    return false;
  }
  return true;
}
Example #10
Source File: index.js    From strapi-plugin-wysiwyg-toastui with MIT License 5 votes vote down vote up
render() {
    const {
      autoFocus,
      className,
      deactivateErrorHighlight,
      disabled,
      error: inputError,
      inputClassName,
      inputDescription,
      inputStyle,
      label,
      name,
      onBlur: handleBlur,
      onChange,
      placeholder,
      resetProps,
      style,
      tabIndex,
      validations,
      value,
      ...rest
    } = this.props;

    return (
      <Error
        inputError={inputError}
        name={name}
        type="text"
        validations={validations}
      >
        {({ canCheck, onBlur, error, dispatch }) => {
          const hasError = error && error !== null;

          return (
            <Wrapper
              className={`${cn(!isEmpty(className) && className)} ${
                hasError ? 'bordered' : ''
              }`}
              style={style}
            >
              <Label htmlFor={name}>{label}</Label>
              <Editor
                {...rest}
                autoFocus={autoFocus}
                className={inputClassName}
                disabled={disabled}
                deactivateErrorHighlight={deactivateErrorHighlight}
                error={hasError}
                name={name}
                onBlur={isFunction(handleBlur) ? handleBlur : onBlur}
                onChange={e => {
                  if (!canCheck) {
                    dispatch({
                      type: 'SET_CHECK',
                    });
                  }

                  dispatch({
                    type: 'SET_ERROR',
                    error: null,
                  });
                  onChange(e);
                }}
                placeholder={placeholder}
                resetProps={resetProps}
                style={inputStyle}
                tabIndex={tabIndex}
                value={value}
              />
              {!hasError && inputDescription && (
                <Description>{inputDescription}</Description>
              )}
              {hasError && <ErrorMessage>{error}</ErrorMessage>}
            </Wrapper>
          );
        }}
      </Error>
    );
  }
Example #11
Source File: Tr.jsx    From kube-design with MIT License 5 votes vote down vote up
renderSelection() {
    const {
      index,
      checkboxRowSpan,
      rowSelection,
      isSelectAll,
      record,
      records,
    } = this.props;

    if (!rowSelection) {
      return null;
    }

    const { selectedRowKeys = [], getCheckboxProps } = rowSelection;

    if (isSelectAll) {
      if (index > 0) {
        return null;
      }

      return (
        <th rowSpan={checkboxRowSpan}>
          <Checkbox
            checked={
              selectedRowKeys.length ===
                records.filter((item) => {
                  if (getCheckboxProps) {
                    const result = getCheckboxProps(item);
                    if (result && result.disabled) {
                      return false;
                    }
                  }
                  return true;
                }).length && selectedRowKeys.length > 0
            }
            indeterminate={
              selectedRowKeys.length < records.length &&
              selectedRowKeys.length > 0
            }
            onChange={this.handleAllChange}
            disabled={records.length <= 0}
          />
        </th>
      );
    }

    let props = {};
    if (isFunction(getCheckboxProps)) {
      props = getCheckboxProps(record);
    }

    return (
      <td>
        <Checkbox
          {...props}
          checked={this.isChecked}
          onChange={this.handleChange}
        />
      </td>
    );
  }
Example #12
Source File: BaseComposeTable.js    From hzero-front with Apache License 2.0 5 votes vote down vote up
componentDidMount() {
    const { onRef } = this.props;
    if (isFunction(onRef)) {
      onRef(this);
    }
  }