1
0

StateMachineHistory.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define("StateMachineHistory", [], factory);
  6. else if(typeof exports === 'object')
  7. exports["StateMachineHistory"] = factory();
  8. else
  9. root["StateMachineHistory"] = factory();
  10. })(this, function() {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // identity function for calling harmony imports with the correct context
  47. /******/ __webpack_require__.i = function(value) { return value; };
  48. /******/
  49. /******/ // define getter function for harmony exports
  50. /******/ __webpack_require__.d = function(exports, name, getter) {
  51. /******/ if(!__webpack_require__.o(exports, name)) {
  52. /******/ Object.defineProperty(exports, name, {
  53. /******/ configurable: false,
  54. /******/ enumerable: true,
  55. /******/ get: getter
  56. /******/ });
  57. /******/ }
  58. /******/ };
  59. /******/
  60. /******/ // getDefaultExport function for compatibility with non-harmony modules
  61. /******/ __webpack_require__.n = function(module) {
  62. /******/ var getter = module && module.__esModule ?
  63. /******/ function getDefault() { return module['default']; } :
  64. /******/ function getModuleExports() { return module; };
  65. /******/ __webpack_require__.d(getter, 'a', getter);
  66. /******/ return getter;
  67. /******/ };
  68. /******/
  69. /******/ // Object.prototype.hasOwnProperty.call
  70. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  71. /******/
  72. /******/ // __webpack_public_path__
  73. /******/ __webpack_require__.p = "";
  74. /******/
  75. /******/ // Load entry module and return exports
  76. /******/ return __webpack_require__(__webpack_require__.s = 1);
  77. /******/ })
  78. /************************************************************************/
  79. /******/ ([
  80. /* 0 */
  81. /***/ (function(module, exports, __webpack_require__) {
  82. "use strict";
  83. //-------------------------------------------------------------------------------------------------
  84. function camelize(label) {
  85. if (label.length === 0)
  86. return label;
  87. var n, result, word, words = label.split(/[_-]/);
  88. // single word with first character already lowercase, return untouched
  89. if ((words.length === 1) && (words[0][0].toLowerCase() === words[0][0]))
  90. return label;
  91. result = words[0].toLowerCase();
  92. for(n = 1 ; n < words.length ; n++) {
  93. result = result + words[n].charAt(0).toUpperCase() + words[n].substring(1).toLowerCase();
  94. }
  95. return result;
  96. }
  97. //-------------------------------------------------------------------------------------------------
  98. camelize.prepended = function(prepend, label) {
  99. label = camelize(label);
  100. return prepend + label[0].toUpperCase() + label.substring(1);
  101. }
  102. //-------------------------------------------------------------------------------------------------
  103. module.exports = camelize;
  104. /***/ }),
  105. /* 1 */
  106. /***/ (function(module, exports, __webpack_require__) {
  107. "use strict";
  108. //-------------------------------------------------------------------------------------------------
  109. var camelize = __webpack_require__(0);
  110. //-------------------------------------------------------------------------------------------------
  111. module.exports = function(options) { options = options || {};
  112. var past = camelize(options.name || options.past || 'history'),
  113. future = camelize( options.future || 'future'),
  114. clear = camelize.prepended('clear', past),
  115. back = camelize.prepended(past, 'back'),
  116. forward = camelize.prepended(past, 'forward'),
  117. canBack = camelize.prepended('can', back),
  118. canForward = camelize.prepended('can', forward),
  119. max = options.max;
  120. var plugin = {
  121. configure: function(config) {
  122. config.addTransitionLifecycleNames(back);
  123. config.addTransitionLifecycleNames(forward);
  124. },
  125. init: function(instance) {
  126. instance[past] = [];
  127. instance[future] = [];
  128. },
  129. lifecycle: function(instance, lifecycle) {
  130. if (lifecycle.event === 'onEnterState') {
  131. instance[past].push(lifecycle.to);
  132. if (max && instance[past].length > max)
  133. instance[past].shift();
  134. if (lifecycle.transition !== back && lifecycle.transition !== forward)
  135. instance[future].length = 0;
  136. }
  137. },
  138. methods: {},
  139. properties: {}
  140. }
  141. plugin.methods[clear] = function() {
  142. this[past].length = 0
  143. this[future].length = 0
  144. }
  145. plugin.properties[canBack] = {
  146. get: function() {
  147. return this[past].length > 1
  148. }
  149. }
  150. plugin.properties[canForward] = {
  151. get: function() {
  152. return this[future].length > 0
  153. }
  154. }
  155. plugin.methods[back] = function() {
  156. if (!this[canBack])
  157. throw Error('no history');
  158. var from = this[past].pop(),
  159. to = this[past].pop();
  160. this[future].push(from);
  161. this._fsm.transit(back, from, to, []);
  162. }
  163. plugin.methods[forward] = function() {
  164. if (!this[canForward])
  165. throw Error('no history');
  166. var from = this.state,
  167. to = this[future].pop();
  168. this._fsm.transit(forward, from, to, []);
  169. }
  170. return plugin;
  171. }
  172. /***/ })
  173. /******/ ]);
  174. });