/
githubmirror
/
react-beautiful-dnd
Обзор
Документация
Войти
/
githubmirror
/
react-beautiful-dnd
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/invariant.js
33 строки
975 B
Alex Reardon
12.0 (#1487)
29 окт 2019, 01:40
Не верифицирован
29 окт 2019, 01:40
24a8e60
Код
Авторство
О чём код?
// @flow /* eslint-disable no-restricted-syntax */ const isProduction: boolean = process.env.NODE_ENV === 'production'; const prefix: string = 'Invariant failed'; // Want to use this: // export class RbdInvariant extends Error { } // But it causes babel to bring in a lot of code export function RbdInvariant(message: string) { this.message = message; } // $FlowFixMe RbdInvariant.prototype.toString = function toString() { return this.message; }; // A copy-paste of tiny-invariant but with a custom error type // Throw an error if the condition fails export function invariant(condition: mixed, message?: string) { if (condition) { return; } if (isProduction) { // In production we strip the message but still throw throw new RbdInvariant(prefix); } else { // When not in production we allow the message to pass through // *This block will be removed in production builds* throw new RbdInvariant(`${prefix}: ${message || ''}`); } }