How to use invariant - 10 common examples

To help you get started, we’ve selected a few invariant 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 lionng429 / react-file-uploader / src / UploadManager.js View on Github external
componentDidMount() {
    // eslint-disable-next-line react/prop-types
    if (this.props.uploadHeader) {
      // eslint-disable-next-line no-console
      console.warn('`props.uploadHeader` is DEPRECATED. Please use `props.uploadHeaderHandler` instead.');
    }

    // eslint-disable-next-line react/prop-types
    if (this.props.formDataParser) {
      // eslint-disable-next-line no-console
      console.warn('`props.formDataParser` is DEPRECATED. Please use `props.uploadDataHandler` instead.');
    }

    invariant(
      !!this.props.uploadUrl,
      'Upload end point must be provided to upload files'
    );

    invariant(
      !!this.props.onUploadEnd,
      'onUploadEnd function must be provided'
    );
  }
github expo / expo / packages / expo-gl / build / GLView.web.js View on Github external
function ensureContext(canvas, contextAttributes) {
    if (!canvas) {
        throw new CodedError('ERR_GL_INVALID', 'Attempting to use the GL context before it has been created.');
    }
    // Apple disables WebGL 2.0 and doesn't provide any way to detect if it's disabled.
    const isIOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);
    const context = (!isIOS && canvas.getContext('webgl2', contextAttributes)) ||
        canvas.getContext('webgl', contextAttributes) ||
        canvas.getContext('webgl-experimental', contextAttributes) ||
        canvas.getContext('experimental-webgl', contextAttributes);
    invariant(context, 'Browser does not support WebGL');
    return asExpoContext(context);
}
function stripNonDOMProps(props) {
github javivelasco / react-css-themr / src / components / themr.js View on Github external
getWrappedInstance() {
      invariant(true,
        'DEPRECATED: To access the wrapped instance, you have to pass ' +
        '{ innerRef: fn } and retrieve with a callback ref style.'
      )

      return this.refs.wrappedInstance
    }
github expo / expo / packages / expo-location / build / Location.js View on Github external
function _validateTaskName(taskName) {
    invariant(taskName && typeof taskName === 'string', '`taskName` must be a non-empty string.');
}
export async function startLocationUpdatesAsync(taskName, options = { accuracy: LocationAccuracy.Balanced }) {
github Yoctol / bottender / packages / bottender / src / cli / providers / messenger / profile.ts View on Github external
export async function setMessengerProfile(ctx: CliContext): Promise {
  const argv = getSubArgs(ctx.argv, {
    '--force': Boolean,
    '-f': '--force',
  });

  const force = argv['--force'];

  try {
    const config = getChannelConfig(Channel.Messenger);

    const { accessToken } = config;

    invariant(
      accessToken,
      '`accessToken` is not found in the `bottender.config.js` file'
    );

    const { profile: _profile } = getChannelConfig(Channel.Messenger);

    const client = MessengerClient.connect({
      accessToken,
    });

    if (force) {
      await client.deleteMessengerProfile(FIELDS);

      print(
        `Successfully delete all ${bold(
          'messenger_profile'
github reduxjs / redux / src / Store.js View on Github external
dispatch(action) {
    invariant(
      isPlainObject(action),
      'Actions must be plain objects. Use custom middleware for async actions.'
    );

    const { reducer } = this;
    this.state = reducer(this.state, action);
    this.listeners.forEach(listener => listener());
    return action;
  }
github react-kit / hookstore / packages / hookstore / src / context.js View on Github external
export function getContextValue(name) {
  const Context = getContext(name);

  invariant(
    Context,
    `store[${name}] has not created yield, please use  as parent component first!`,
  );

  return Context._currentValue;
}
github pCloud / pcloud-sdk-js / src / client / methods / movefile.js View on Github external
export default ({ client }: MethodApi) => (fileid: number, tofolderid: number): Promise => {
  invariant(typeof fileid === "number", "`fileid` must be number.");
  invariant(fileid !== 0, "`fileid` cannot be 0.");
  invariant(tofolderid, "`tofolderid` is required.");

  return client
    .api("renamefile", {
      params: {
        fileid: fileid,
        tofolderid: tofolderid,
      },
    })
    .then(response => response.metadata);
};
github angular-redux / ng-redux / src / components / connector.js View on Github external
return (target) => {

      invariant(
        isFunction(target) || isObject(target),
        'The target parameter passed to connect must be a Function or a object.'
        );

      //Initial update
      updateTarget(target, slice, boundActionCreators);

      const unsubscribe = store.subscribe(() => {
        const nextSlice = getStateSlice(store.getState(), finalMapStateToTarget);
        if (!shallowEqual(slice, nextSlice)) {
          updateTarget(target, nextSlice, boundActionCreators, slice);
          slice = nextSlice;
        }
      });
      return unsubscribe;
    }

invariant

invariant

MIT
Latest version published 6 years ago

Package Health Score

74 / 100
Full package analysis