Advertisement
Guest User

TypeScript Flux Dispatcher - invariant support class

a guest
Jan 7th, 2015
720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. /**
  2. * Copyright (c) 2014, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. * @providesModule invariant
  10. */
  11.  
  12. // 2014-10-16 Dan Roberts: Minor adjustments for use as TypeScript with support for the option "Allow implicit 'any' types" to be disabled. The copyright message is maintained from the original file at https://github.com/facebook/flux/blob/master/src/invairant.js
  13.  
  14. /**
  15. * Use invariant() to assert state which your program assumes to be true.
  16. *
  17. * Provide sprintf-style format (only %s is supported) and arguments
  18. * to provide information about what broke and what you were
  19. * expecting.
  20. *
  21. * The invariant message will be stripped in production, but the invariant
  22. * will remain to ensure logic does not differ in production.
  23. */
  24.  
  25. var invariant = function (condition: boolean, format: string, a?: any, b?: any, c?: any, d?: any, e?: any, f?: any): void {
  26. if (!condition) {
  27. var error: Error;
  28. if (format === undefined) {
  29. error = new Error(
  30. 'Minified exception occurred; use the non-minified dev environment ' +
  31. 'for the full error message and additional helpful warnings.'
  32. );
  33. } else {
  34. var args = [a, b, c, d, e, f];
  35. var argIndex = 0;
  36. error = new Error(
  37. 'Invariant Violation: ' +
  38. format.replace(/%s/g, function () { return args[argIndex++]; })
  39. );
  40. }
  41.  
  42. (<any>error).framesToPop = 1; // we don't care about invariant's own frame
  43. throw error;
  44. }
  45. };
  46.  
  47. export = invariant;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement