rollex 1.0.0.pre.rc.1 → 1.0.0.pre.rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ad0f0ba1285add1c1bcdb04414f9c579e39e2bc
4
- data.tar.gz: fda8553769da16f94746c9487e7e51f5cead2b6b
3
+ metadata.gz: 33637c95180b914ae5241f2995cc617d3b22a180
4
+ data.tar.gz: d4223bc0f521d7112991422122d712866fe4d841
5
5
  SHA512:
6
- metadata.gz: 739a58c7a5071664bd69e939c14e87d240cde02993c59219ee05b60ffc2356b4b15283a27ab4cc6036a9a143afb4c2a03a7892512442490fad92add2e1ad852b
7
- data.tar.gz: 06bd190f50d87db53705476f139359dc5c4f6537c433135b8e9c24171f2119f1028a40ee2d484babb809eb3bedd3f4be3a00848c53e7a839770cc199edf7f374
6
+ metadata.gz: '099d2622a38c712289b42690e2a5eaafe7412724c307e59a81091f03346ebc355b5a45703ef4ac87cd29ddb6f3880aee9f3d8518c0540503937ff0f9628f654e'
7
+ data.tar.gz: 3a017b20f6224a319ea4a51aed75684692177320215e1a842fda3555dbcee576c100e2851e00e7690263de2edf4cc2ca51ca5de12a235b9276809b9b68ce5969
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Rollex
3
3
  module Rails
4
- VERSION = "1.0.0-rc.1"
4
+ VERSION = "1.0.0-rc.3"
5
5
  end
6
6
  end
@@ -92,8 +92,8 @@ module.exports = __WEBPACK_EXTERNAL_MODULE_0__;
92
92
  Object.defineProperty(exports, "__esModule", {
93
93
  value: true
94
94
  });
95
-
96
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
95
+ exports.digitPropTypes = undefined;
96
+ exports.decorateDigit = decorateDigit;
97
97
 
98
98
  var _react = __webpack_require__(0);
99
99
 
@@ -101,12 +101,6 @@ var _react2 = _interopRequireDefault(_react);
101
101
 
102
102
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
103
103
 
104
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
105
-
106
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
107
-
108
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
109
-
110
104
  var _React$PropTypes = _react2.default.PropTypes,
111
105
  objectOf = _React$PropTypes.objectOf,
112
106
  any = _React$PropTypes.any,
@@ -115,50 +109,28 @@ var _React$PropTypes = _react2.default.PropTypes,
115
109
  func = _React$PropTypes.func;
116
110
 
117
111
  /**
118
- * Common logic for {@link StaticCounterDigit} and {@link AnimatedCounterDigit}.
112
+ * @property {string} digit - digit to display
113
+ * @property {number} radix
114
+ * @property {Object} digitMap - a map for transforming particular digits
115
+ * @property {function(digit: number)} digitWrapper - a function for wrapping mapped digits
119
116
  */
120
117
 
121
- var AbstractCounterDigit = function (_React$Component) {
122
- _inherits(AbstractCounterDigit, _React$Component);
123
-
124
- function AbstractCounterDigit() {
125
- _classCallCheck(this, AbstractCounterDigit);
126
-
127
- return _possibleConstructorReturn(this, (AbstractCounterDigit.__proto__ || Object.getPrototypeOf(AbstractCounterDigit)).apply(this, arguments));
128
- }
129
-
130
- _createClass(AbstractCounterDigit, [{
131
- key: 'decorateDigit',
132
-
133
-
134
- /**
135
- * Decorates given digit according to radix, digit map and digit wrapper.
136
- * @param {number} digit
137
- * @return {string} decoratedDigit
138
- */
139
- value: function decorateDigit(digit) {
140
- var digitString = digit.toString(this.props.radix);
141
- return this.props.digitWrapper(this.props.digitMap[digitString] || digitString);
142
- }
143
- /**
144
- * @property {string} digit - digit to display
145
- * @property {number} radix
146
- * @property {Object} digitMap - a map for transforming particular digits
147
- * @property {function(digit: number)} digitWrapper - a function for wrapping mapped digits
148
- */
149
-
150
- }]);
151
-
152
- return AbstractCounterDigit;
153
- }(_react2.default.Component);
154
-
155
- AbstractCounterDigit.propTypes = {
118
+ var digitPropTypes = exports.digitPropTypes = {
156
119
  digit: string.isRequired,
157
120
  radix: number.isRequired,
158
121
  digitMap: objectOf(any).isRequired,
159
122
  digitWrapper: func.isRequired
160
123
  };
161
- exports.default = AbstractCounterDigit;
124
+
125
+ /**
126
+ * Decorates given digit according to radix, digit map and digit wrapper.
127
+ * @param {number} digit
128
+ * @return {string} decoratedDigit
129
+ */
130
+ function decorateDigit(digit, props) {
131
+ var digitString = digit.toString(props.radix);
132
+ return props.digitWrapper(props.digitMap[digitString] || digitString);
133
+ }
162
134
 
163
135
  /***/ }),
164
136
  /* 2 */
@@ -364,7 +336,7 @@ var Counter = function (_React$Component) {
364
336
  */
365
337
  var _this = _possibleConstructorReturn(this, (Counter.__proto__ || Object.getPrototypeOf(Counter)).call(this, props));
366
338
 
367
- _this.state = new _counterBuilder2.default(_this).buildInitialState();
339
+ _this.state = new _counterBuilder2.default(props).buildInitialState();
368
340
 
369
341
  /**
370
342
  * Creates a function bound to "this"
@@ -382,7 +354,7 @@ var Counter = function (_React$Component) {
382
354
  }, {
383
355
  key: 'componentWillUnmount',
384
356
  value: function componentWillUnmount() {
385
- if (!this.props.frozen && !this.state.stopped) this.stop();
357
+ if (!this.props.frozen && !this.stopped) this.stop();
386
358
  }
387
359
 
388
360
  /**
@@ -409,9 +381,8 @@ var Counter = function (_React$Component) {
409
381
  }, {
410
382
  key: 'start',
411
383
  value: function start() {
412
- _globalIntervals2.default.ensureExistence(this.props.interval);
413
- _globalIntervals2.default.subscribe(this.props.interval, this.boundTick);
414
- this.setState({ stopped: false });
384
+ this.unsubscribe = _globalIntervals2.default.subscribe(this.props.interval, this.boundTick);
385
+ this.stopped = false;
415
386
  }
416
387
 
417
388
  /**
@@ -421,9 +392,9 @@ var Counter = function (_React$Component) {
421
392
  }, {
422
393
  key: 'stop',
423
394
  value: function stop() {
424
- _globalIntervals2.default.unsubscribe(this.props.interval, this.boundTick);
425
- _globalIntervals2.default.cleanup(this.props.interval);
426
- this.setState({ stopped: true });
395
+ if (!this.unsubscribe) return;
396
+ this.unsubscribe();
397
+ this.stopped = true;
427
398
  }
428
399
 
429
400
  /**
@@ -628,9 +599,7 @@ var _reactDom = __webpack_require__(10);
628
599
 
629
600
  var _reactDom2 = _interopRequireDefault(_reactDom);
630
601
 
631
- var _AbstractCounterDigit2 = __webpack_require__(1);
632
-
633
- var _AbstractCounterDigit3 = _interopRequireDefault(_AbstractCounterDigit2);
602
+ var _counterDigitHelper = __webpack_require__(1);
634
603
 
635
604
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
636
605
 
@@ -669,8 +638,8 @@ function forceReflow(element) {
669
638
  * />
670
639
  */
671
640
 
672
- var AnimatedCounterDigit = function (_AbstractCounterDigit) {
673
- _inherits(AnimatedCounterDigit, _AbstractCounterDigit);
641
+ var AnimatedCounterDigit = function (_React$Component) {
642
+ _inherits(AnimatedCounterDigit, _React$Component);
674
643
 
675
644
  function AnimatedCounterDigit(props) {
676
645
  _classCallCheck(this, AnimatedCounterDigit);
@@ -687,11 +656,11 @@ var AnimatedCounterDigit = function (_AbstractCounterDigit) {
687
656
  }
688
657
  };
689
658
 
690
- var singleDigitHeight = 100 / (_this.props.maxValue + 2);
691
- var upperZeroPosition = -singleDigitHeight * (_this.props.radix - _this.props.maxValue - 1);
692
- var lowerZeroPosition = -singleDigitHeight * _this.props.radix;
693
- var initialZeroPosition = _this.props.direction === 'down' ? lowerZeroPosition : upperZeroPosition;
694
- var finalZeroPosition = _this.props.direction === 'down' ? upperZeroPosition : lowerZeroPosition;
659
+ var singleDigitHeight = 100 / (props.maxValue + 2);
660
+ var upperZeroPosition = -singleDigitHeight * (props.radix - props.maxValue - 1);
661
+ var lowerZeroPosition = -singleDigitHeight * props.radix;
662
+ var initialZeroPosition = props.direction === 'down' ? lowerZeroPosition : upperZeroPosition;
663
+ var finalZeroPosition = props.direction === 'down' ? upperZeroPosition : lowerZeroPosition;
695
664
 
696
665
  _this.state = {
697
666
  initialZeroPosition: initialZeroPosition,
@@ -702,6 +671,10 @@ var AnimatedCounterDigit = function (_AbstractCounterDigit) {
702
671
  return _this;
703
672
  }
704
673
  /**
674
+ * @property {string} digit - digit to display
675
+ * @property {number} radix
676
+ * @property {Object} digitMap - a map for transforming particular digits
677
+ * @property {function(digit: number)} digitWrapper - a function for wrapping mapped digits
705
678
  * @property {string} direction - counting direction
706
679
  * @property {number} maxValue - maximum value used to build a digit lane
707
680
  * @property {string} easingFunction - easing function for transitions
@@ -735,7 +708,7 @@ var AnimatedCounterDigit = function (_AbstractCounterDigit) {
735
708
  return _react2.default.createElement(
736
709
  'div',
737
710
  { key: key || digit, className: 'rollex-digit-lane-label' },
738
- this.decorateDigit(digit)
711
+ (0, _counterDigitHelper.decorateDigit)(digit, this.props)
739
712
  );
740
713
  }
741
714
 
@@ -801,9 +774,9 @@ var AnimatedCounterDigit = function (_AbstractCounterDigit) {
801
774
  }]);
802
775
 
803
776
  return AnimatedCounterDigit;
804
- }(_AbstractCounterDigit3.default);
777
+ }(_react2.default.Component);
805
778
 
806
- AnimatedCounterDigit.propTypes = _extends({}, _AbstractCounterDigit3.default.propTypes, {
779
+ AnimatedCounterDigit.propTypes = _extends({}, _counterDigitHelper.digitPropTypes, {
807
780
  direction: string.isRequired,
808
781
  maxValue: number.isRequired,
809
782
  easingFunction: string.isRequired,
@@ -821,8 +794,7 @@ exports.default = AnimatedCounterDigit;
821
794
  Object.defineProperty(exports, "__esModule", {
822
795
  value: true
823
796
  });
824
-
825
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
797
+ exports.default = CounterSegment;
826
798
 
827
799
  var _react = __webpack_require__(0);
828
800
 
@@ -838,12 +810,6 @@ var _StaticCounterDigit2 = _interopRequireDefault(_StaticCounterDigit);
838
810
 
839
811
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
840
812
 
841
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
842
-
843
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
844
-
845
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
846
-
847
813
  var _React$PropTypes = _react2.default.PropTypes,
848
814
  arrayOf = _React$PropTypes.arrayOf,
849
815
  object = _React$PropTypes.object,
@@ -863,6 +829,29 @@ var PERIOD_LIMITS = {
863
829
  'days': 0
864
830
  };
865
831
 
832
+ /**
833
+ * @property {string[]} digits - digits to display
834
+ * @property {string} period
835
+ * @property {number} radix
836
+ * @property {string} direction - counting direction
837
+ * @property {string} easingFunction - easing function to use for digit transitions
838
+ * @property {number} easingDuration - duration of digit transitions
839
+ * @property {Object} digitMap - a map for transforming particular digits
840
+ * @property {function(digit: number)} digitWrapper - a function for wrapping mapped digits
841
+ * @property {string} label
842
+ */
843
+ CounterSegment.propTypes = {
844
+ digits: arrayOf(string).isRequired,
845
+ period: string.isRequired,
846
+ radix: number.isRequired,
847
+ direction: string.isRequired,
848
+ easingFunction: string,
849
+ easingDuration: number.isRequired,
850
+ digitMap: object.isRequired,
851
+ digitWrapper: func.isRequired,
852
+ label: string
853
+ };
854
+
866
855
  /**
867
856
  * Counter segment component.
868
857
  * @example
@@ -876,125 +865,67 @@ var PERIOD_LIMITS = {
876
865
  * digitWrapper={(digit) => digit}
877
866
  * />
878
867
  */
868
+ function CounterSegment(props) {
869
+ /**
870
+ * Gets maximum value for period's digit with account for radix.
871
+ * Used for building digit lanes in {@link AnimatedCounterDigit}.
872
+ * @param {number} index - digit's index in number
873
+ * @return {number} maxValue
874
+ */
875
+ function getMaxValue(index) {
876
+ var maxValue = PERIOD_LIMITS[props.period];
877
+ if (!maxValue) return props.radix - 1;
879
878
 
880
- var CounterSegment = function (_React$Component) {
881
- _inherits(CounterSegment, _React$Component);
882
-
883
- function CounterSegment() {
884
- _classCallCheck(this, CounterSegment);
885
-
886
- return _possibleConstructorReturn(this, (CounterSegment.__proto__ || Object.getPrototypeOf(CounterSegment)).apply(this, arguments));
879
+ var maxValueString = maxValue.toString(props.radix);
880
+ var maxDigitPos = maxValueString.length;
881
+ return index === props.digits.length - maxDigitPos ? parseInt(maxValueString[0]) : props.radix - 1;
887
882
  }
888
883
 
889
- _createClass(CounterSegment, [{
890
- key: 'getMaxValue',
891
-
892
-
893
- /**
894
- * OPTIMIZE: this probably shouldn't be done in buildDigits. Perhaps we could perform calculations
895
- * for each possible index it in the constructor, but only for animated counters.
896
- *
897
- * Gets maximum value for period's digit with account for radix.
898
- * Used for building digit lanes in {@link AnimatedCounterDigit}.
899
- * @param {number} index - digit's index in number
900
- * @return {number} maxValue
901
- */
902
- value: function getMaxValue(index) {
903
- var maxValue = PERIOD_LIMITS[this.props.period];
904
- if (!maxValue) return this.props.radix - 1;
905
-
906
- var maxValueString = maxValue.toString(this.props.radix);
907
- var maxDigitPos = maxValueString.length;
908
- return index === this.props.digits.length - maxDigitPos ? parseInt(maxValueString[0]) : this.props.radix - 1;
909
- }
910
-
911
- /**
912
- * Maps digits to corresponding components according to easing function.
913
- * @return {ReactElement[]}
914
- */
915
-
916
- /**
917
- * @property {string[]} digits - digits to display
918
- * @property {string} period
919
- * @property {number} radix
920
- * @property {string} direction - counting direction
921
- * @property {string} easingFunction - easing function to use for digit transitions
922
- * @property {number} easingDuration - duration of digit transitions
923
- * @property {Object} digitMap - a map for transforming particular digits
924
- * @property {function(digit: number)} digitWrapper - a function for wrapping mapped digits
925
- * @property {string} label
926
- */
927
-
928
- }, {
929
- key: 'buildDigits',
930
- value: function buildDigits() {
931
- var _this2 = this;
932
-
933
- return this.props.digits.map(function (digit, index) {
934
- if (_this2.props.easingFunction) {
935
- return _react2.default.createElement(_AnimatedCounterDigit2.default, {
936
- key: index,
937
- digit: digit,
938
- maxValue: _this2.getMaxValue(index),
939
- radix: _this2.props.radix,
940
- direction: _this2.props.direction,
941
- easingFunction: _this2.props.easingFunction,
942
- easingDuration: _this2.props.easingDuration,
943
- digitMap: _this2.props.digitMap,
944
- digitWrapper: _this2.props.digitWrapper
945
- });
946
- } else {
947
- return _react2.default.createElement(_StaticCounterDigit2.default, {
948
- key: index,
949
- digit: digit,
950
- radix: _this2.props.radix,
951
- digitMap: _this2.props.digitMap,
952
- digitWrapper: _this2.props.digitWrapper
953
- });
954
- }
955
- });
956
- }
957
-
958
- /**
959
- * Renders the segment.
960
- * @return {ReactElement} counter segment
961
- */
962
-
963
- }, {
964
- key: 'render',
965
- value: function render() {
966
- return _react2.default.createElement(
967
- 'div',
968
- { className: 'rollex-segment' },
969
- _react2.default.createElement(
970
- 'div',
971
- { className: 'rollex-digits', style: { overflow: 'hidden' } },
972
- this.buildDigits()
973
- ),
974
- _react2.default.createElement(
975
- 'div',
976
- { className: 'rollex-label' },
977
- this.props.label
978
- )
979
- );
980
- }
981
- }]);
982
-
983
- return CounterSegment;
984
- }(_react2.default.Component);
884
+ /**
885
+ * Maps digits to corresponding components according to easing function.
886
+ * @return {ReactElement[]}
887
+ */
888
+ function buildDigits() {
889
+ return props.digits.map(function (digit, index) {
890
+ if (props.easingFunction) {
891
+ return _react2.default.createElement(_AnimatedCounterDigit2.default, {
892
+ key: index,
893
+ digit: digit,
894
+ maxValue: getMaxValue(index),
895
+ radix: props.radix,
896
+ direction: props.direction,
897
+ easingFunction: props.easingFunction,
898
+ easingDuration: props.easingDuration,
899
+ digitMap: props.digitMap,
900
+ digitWrapper: props.digitWrapper
901
+ });
902
+ } else {
903
+ return _react2.default.createElement(_StaticCounterDigit2.default, {
904
+ key: index,
905
+ digit: digit,
906
+ radix: props.radix,
907
+ digitMap: props.digitMap,
908
+ digitWrapper: props.digitWrapper
909
+ });
910
+ }
911
+ });
912
+ }
985
913
 
986
- CounterSegment.propTypes = {
987
- digits: arrayOf(string).isRequired,
988
- period: string.isRequired,
989
- radix: number.isRequired,
990
- direction: string.isRequired,
991
- easingFunction: string,
992
- easingDuration: number.isRequired,
993
- digitMap: object.isRequired,
994
- digitWrapper: func.isRequired,
995
- label: string
996
- };
997
- exports.default = CounterSegment;
914
+ return _react2.default.createElement(
915
+ 'div',
916
+ { className: 'rollex-segment' },
917
+ _react2.default.createElement(
918
+ 'div',
919
+ { className: 'rollex-digits', style: { overflow: 'hidden' } },
920
+ buildDigits()
921
+ ),
922
+ _react2.default.createElement(
923
+ 'div',
924
+ { className: 'rollex-label' },
925
+ props.label
926
+ )
927
+ );
928
+ }
998
929
 
999
930
  /***/ }),
1000
931
  /* 6 */
@@ -1078,24 +1009,23 @@ exports.default = CounterSegmentSeparator;
1078
1009
  Object.defineProperty(exports, "__esModule", {
1079
1010
  value: true
1080
1011
  });
1081
-
1082
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
1012
+ exports.default = StaticCounterDigit;
1083
1013
 
1084
1014
  var _react = __webpack_require__(0);
1085
1015
 
1086
1016
  var _react2 = _interopRequireDefault(_react);
1087
1017
 
1088
- var _AbstractCounterDigit2 = __webpack_require__(1);
1089
-
1090
- var _AbstractCounterDigit3 = _interopRequireDefault(_AbstractCounterDigit2);
1018
+ var _counterDigitHelper = __webpack_require__(1);
1091
1019
 
1092
1020
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1093
1021
 
1094
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1095
-
1096
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
1097
-
1098
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
1022
+ /**
1023
+ * @property {string} digit - digit to display
1024
+ * @property {number} radix
1025
+ * @property {Object} digitMap - a map for transforming particular digits
1026
+ * @property {function(digit: number)} digitWrapper - a function for wrapping mapped digits
1027
+ */
1028
+ StaticCounterDigit.propTypes = _counterDigitHelper.digitPropTypes;
1099
1029
 
1100
1030
  /**
1101
1031
  * Static digit component.
@@ -1108,35 +1038,13 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
1108
1038
  * digitWrapper={(digit) => digit}
1109
1039
  * />
1110
1040
  */
1111
- var StaticCounterDigit = function (_AbstractCounterDigit) {
1112
- _inherits(StaticCounterDigit, _AbstractCounterDigit);
1113
-
1114
- function StaticCounterDigit() {
1115
- _classCallCheck(this, StaticCounterDigit);
1116
-
1117
- return _possibleConstructorReturn(this, (StaticCounterDigit.__proto__ || Object.getPrototypeOf(StaticCounterDigit)).apply(this, arguments));
1118
- }
1119
-
1120
- _createClass(StaticCounterDigit, [{
1121
- key: 'render',
1122
-
1123
- /**
1124
- * Renders the digit.
1125
- * @return {ReactElement} digit
1126
- */
1127
- value: function render() {
1128
- return _react2.default.createElement(
1129
- 'div',
1130
- { className: 'rollex-digit' },
1131
- this.decorateDigit(this.props.digit)
1132
- );
1133
- }
1134
- }]);
1135
-
1136
- return StaticCounterDigit;
1137
- }(_AbstractCounterDigit3.default);
1138
-
1139
- exports.default = StaticCounterDigit;
1041
+ function StaticCounterDigit(props) {
1042
+ return _react2.default.createElement(
1043
+ 'div',
1044
+ { className: 'rollex-digit' },
1045
+ (0, _counterDigitHelper.decorateDigit)(props.digit, props)
1046
+ );
1047
+ }
1140
1048
 
1141
1049
  /***/ }),
1142
1050
  /* 8 */
@@ -1220,16 +1128,15 @@ var CounterBuilder = function () {
1220
1128
  }
1221
1129
 
1222
1130
  /**
1223
- * @param {Counter} counter
1131
+ * @param {object} props
1224
1132
  */
1225
1133
 
1226
1134
  }]);
1227
1135
 
1228
- function CounterBuilder(counter) {
1136
+ function CounterBuilder(props) {
1229
1137
  _classCallCheck(this, CounterBuilder);
1230
1138
 
1231
- this.counter = counter;
1232
- this.props = counter.props;
1139
+ this.props = props;
1233
1140
  this.state = {};
1234
1141
  }
1235
1142
 
@@ -1447,51 +1354,68 @@ Object.defineProperty(exports, "__esModule", {
1447
1354
  */
1448
1355
  var GlobalIntervals = {
1449
1356
  /**
1450
- * Ensures existence of an interval.
1357
+ * Returns an interval with a given duration. Creates one if it doesn't exist.
1451
1358
  * @param {!number} duration - interval duration in milliseconds
1359
+ * @return {object}
1452
1360
  */
1453
- ensureExistence: function ensureExistence(duration) {
1454
- if (!window.rollexIntervals) window.rollexIntervals = {};
1455
- if (!window.rollexIntervals[duration]) {
1456
- window.rollexIntervals[duration] = {
1457
- interval: setInterval(function () {
1458
- window.dispatchEvent(new CustomEvent("rollex:tick:" + duration));
1459
- }, duration, false),
1460
- counterCount: 0
1361
+ getInterval: function getInterval(duration) {
1362
+ if (!this.intervals[duration]) {
1363
+ var intervalsObj = this.intervals[duration] = {
1364
+ callbacks: []
1461
1365
  };
1366
+ intervalsObj.interval = setInterval(function () {
1367
+ this.callbacks.forEach(function (cb) {
1368
+ return cb();
1369
+ });
1370
+ }.bind(intervalsObj), duration, false);
1462
1371
  }
1372
+ return this.intervals[duration];
1463
1373
  },
1464
1374
 
1465
1375
  /**
1466
- * Cleans up an interval.
1467
1376
  * @param {!number} duration - interval duration in milliseconds
1468
1377
  */
1469
- cleanup: function cleanup(duration) {
1470
- if (window.rollexIntervals[duration].counterCount === 0) {
1471
- clearInterval(window.rollexIntervals[duration].interval);
1472
- delete window.rollexIntervals[duration];
1473
- }
1378
+ removeIntervalWithDuration: function removeIntervalWithDuration(duration) {
1379
+ clearInterval(this.intervals[duration].interval);
1380
+ delete this.intervals[duration];
1474
1381
  },
1475
1382
 
1476
1383
  /**
1477
- * Adds a subscriber to an interval.
1384
+ * Adds a listener to an interval.
1478
1385
  * @param {!number} duration - interval duration in milliseconds
1479
- * @param {!Object|function} subscriber
1386
+ * @param {!function} callback - listener
1387
+ * @return {function} unsubscribe
1388
+ */
1389
+ subscribe: function subscribe(duration, callback) {
1390
+ var _this = this;
1391
+
1392
+ var callbacks = this.getInterval(duration).callbacks;
1393
+ callbacks.push(callback);
1394
+ return function () {
1395
+ return _this.removeListener(duration, callback);
1396
+ };
1397
+ },
1398
+
1399
+ /**
1400
+ * Removes a listener from its interval. Stops the interval if it no longer has listeners.
1401
+ * @param {!number} duration
1402
+ * @param {!function} cb - listener
1480
1403
  */
1481
- subscribe: function subscribe(duration, subscriber) {
1482
- window.rollexIntervals[duration].counterCount += 1;
1483
- window.addEventListener("rollex:tick:" + duration, subscriber, false);
1404
+ removeListener: function removeListener(duration, cb) {
1405
+ var interval = this.intervals[duration];
1406
+ var callbacks = interval.callbacks;
1407
+
1408
+ if (callbacks.length > 1) {
1409
+ callbacks.splice(callbacks.indexOf(cb));
1410
+ } else {
1411
+ this.removeIntervalWithDuration(duration);
1412
+ }
1484
1413
  },
1485
1414
 
1486
1415
  /**
1487
- * Removes a subscriber from an interval.
1488
- * @param {!number} duration - interval duration in milliseconds
1489
- * @param {!Object|function} subscriber
1416
+ * Stores global intervals
1490
1417
  */
1491
- unsubscribe: function unsubscribe(duration, subscriber) {
1492
- window.removeEventListener("rollex:tick:" + duration, subscriber, false);
1493
- window.rollexIntervals[duration].counterCount -= 1;
1494
- }
1418
+ intervals: {}
1495
1419
  };
1496
1420
 
1497
1421
  exports.default = GlobalIntervals;
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rollex
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.rc.1
4
+ version: 1.0.0.pre.rc.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Komarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-16 00:00:00.000000000 Z
11
+ date: 2017-03-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: