Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

uber / deck.gl / 13779

18 Sep 2019 - 0:00 coverage decreased (-2.9%) to 79.902%
13779

Pull #3623

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
beta.2
Pull Request #3623: Bump dependency versions

3405 of 4619 branches covered (73.72%)

Branch coverage included in aggregate %.

7031 of 8442 relevant lines covered (83.29%)

5687.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.41
/modules/core/src/controllers/transition-manager.js
1
import LinearInterpolator from '../transitions/linear-interpolator';
16×
2
import Transition from '../transitions/transition';
3
import assert from '../utils/assert';
4

5
const noop = () => {};
1×
6

7
export const TRANSITION_EVENTS = {
1×
8
  BREAK: 1,
9
  SNAP_TO_END: 2,
10
  IGNORE: 3
11
};
12

13
const DEFAULT_PROPS = {
1×
14
  transitionDuration: 0,
15
  transitionEasing: t => t,
5×
16
  transitionInterpolator: new LinearInterpolator(),
17
  transitionInterruption: TRANSITION_EVENTS.BREAK,
18
  onTransitionStart: noop,
19
  onTransitionInterrupt: noop,
20
  onTransitionEnd: noop
21
};
22

23
export default class TransitionManager {
24
  constructor(ControllerState, props = {}) {
Branches [[0, 0]] missed.
25
    assert(ControllerState);
10×
26
    this.ControllerState = ControllerState;
10×
27
    this.props = Object.assign({}, DEFAULT_PROPS, props);
10×
28
    this.propsInTransition = null;
10×
29
    this.transition = new Transition({timeline: props.timeline});
10×
30

31
    this.onViewStateChange = props.onViewStateChange;
10×
32

33
    this._onTransitionUpdate = this._onTransitionUpdate.bind(this);
10×
34
  }
35

36
  finalize() {
37
    this.transition.cancel();
2×
38
  }
39

40
  // Returns current transitioned viewport.
41
  getViewportInTransition() {
UNCOV
42
    return this.propsInTransition;
!
43
  }
44

45
  // Process the vewiport change, either ignore or trigger a new transition.
46
  // Return true if a new transition is triggered, false otherwise.
47
  processViewStateChange(nextProps) {
48
    let transitionTriggered = false;
197×
49
    const currentProps = this.props;
197×
50
    // Set this.props here as '_triggerTransition' calls '_updateViewport' that uses this.props.
51
    nextProps = Object.assign({}, DEFAULT_PROPS, nextProps);
197×
52
    this.props = nextProps;
197×
53

54
    // NOTE: Be cautious re-ordering statements in this function.
55
    if (this._shouldIgnoreViewportChange(currentProps, nextProps)) {
197×
56
      return transitionTriggered;
159×
57
    }
58

59
    if (this._isTransitionEnabled(nextProps)) {
Branches [[2, 1]] missed. 38×
60
      const startProps = Object.assign(
38×
61
        {},
62
        currentProps,
63
        this.transition.interruption === TRANSITION_EVENTS.SNAP_TO_END
Branches [[3, 0]] missed.
64
          ? this.transition.endProps
65
          : this.propsInTransition || currentProps
66
      );
67

68
      this._triggerTransition(startProps, nextProps);
38×
69

70
      transitionTriggered = true;
38×
71
    } else {
UNCOV
72
      this.transition.cancel();
!
73
    }
74

75
    return transitionTriggered;
38×
76
  }
77

78
  updateTransition() {
79
    this.transition.update();
42×
80
  }
81

82
  // Helper methods
83

84
  _isTransitionEnabled(props) {
85
    return props.transitionDuration > 0 && props.transitionInterpolator;
220×
86
  }
87

88
  _isUpdateDueToCurrentTransition(props) {
89
    if (this.transition.inProgress) {
Branches [[6, 1]] missed. 53×
90
      return this.transition.interpolator.arePropsEqual(props, this.propsInTransition);
53×
91
    }
UNCOV
92
    return false;
!
93
  }
94

95
  _shouldIgnoreViewportChange(currentProps, nextProps) {
96
    if (this.transition.inProgress) {
197×
97
      // Ignore update if it is requested to be ignored
98
      return (
53×
99
        this.transition.interruption === TRANSITION_EVENTS.IGNORE ||
100
        // Ignore update if it is due to current active transition.
101
        this._isUpdateDueToCurrentTransition(nextProps)
102
      );
103
    } else if (this._isTransitionEnabled(nextProps)) {
144×
104
      // Ignore if none of the viewport props changed.
105
      return nextProps.transitionInterpolator.arePropsEqual(currentProps, nextProps);
7×
106
    }
107
    return true;
137×
108
  }
109

110
  _triggerTransition(startProps, endProps) {
111
    assert(this._isTransitionEnabled(endProps), 'Transition is not enabled');
38×
112

113
    const startViewstate = new this.ControllerState(startProps);
38×
114
    const endViewStateProps = new this.ControllerState(endProps).shortestPathFrom(startViewstate);
38×
115

116
    const initialProps = endProps.transitionInterpolator.initializeProps(
38×
117
      startProps,
118
      endViewStateProps
119
    );
120

121
    this.propsInTransition = {};
38×
122
    this.transition.start({
38×
123
      duration: endProps.transitionDuration,
124
      easing: endProps.transitionEasing,
125
      interpolator: endProps.transitionInterpolator,
126
      interruption: endProps.transitionInterruption,
127

128
      startProps: initialProps.start,
129
      endProps: initialProps.end,
130

131
      onStart: endProps.onTransitionStart,
132
      onUpdate: this._onTransitionUpdate,
133
      onInterrupt: this._onTransitionEnd(endProps.onTransitionInterrupt),
134
      onEnd: this._onTransitionEnd(endProps.onTransitionEnd)
135
    });
136
    this.updateTransition();
38×
137
  }
138

139
  _onTransitionEnd(callback) {
140
    return transition => {
76×
141
      this.propsInTransition = null;
34×
142
      callback(transition);
34×
143
    };
144
  }
145

146
  _onTransitionUpdate(transition) {
147
    // NOTE: Be cautious re-ordering statements in this function.
148
    const {interpolator, startProps, endProps, time} = transition;
39×
149

150
    const viewport = interpolator.interpolateProps(startProps, endProps, time);
39×
151

152
    // This gurantees all props (e.g. bearing, longitude) are normalized
153
    // So when viewports are compared they are in same range.
154
    this.propsInTransition = new this.ControllerState(
39×
155
      Object.assign({}, this.props, viewport)
156
    ).getViewportProps();
157

158
    if (this.onViewStateChange) {
39×
159
      this.onViewStateChange({
3×
160
        viewState: this.propsInTransition,
161
        interactionState: {inTransition: true},
162
        oldViewState: this.props
163
      });
164
    }
165
  }
166
}
167

168
TransitionManager.defaultProps = DEFAULT_PROPS;
1×
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2019 Coveralls, LLC