Skip to content

Commit

Permalink
fix: animation FlowManager subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
romelperez committed Jan 13, 2020
1 parent de8ec0f commit 1e9a9f8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
12 changes: 10 additions & 2 deletions packages/animation/src/makeFlowManager/makeFlowManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ function makeFlowManager (component) {

const { parentEnergyContext, imperative } = component.props;

if (parentEnergyContext && parentEnergyContext.type === STREAM && !imperative) {
if (parentEnergyContext && parentEnergyContext.type === STREAM) {
if (imperative) {
return;
}

parentEnergyContext._subscribe(component);
}
else if (component.isActivated()) {
Expand Down Expand Up @@ -44,7 +48,11 @@ function makeFlowManager (component) {

const { parentEnergyContext, imperative } = component.props;

if (parentEnergyContext && parentEnergyContext.type === STREAM && !imperative) {
if (parentEnergyContext && parentEnergyContext.type === STREAM) {
if (imperative) {
return;
}

parentEnergyContext._unsubscribe(component);
}
}
Expand Down
50 changes: 37 additions & 13 deletions packages/animation/src/makeFlowManager/makeFlowManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,52 @@ import { makeFlowManager } from './makeFlowManager';
import { STREAM } from '../constants';

describe('checkMount()', () => {
test('Should subscribe to parent node if parent is stream, animated, outsourced', () => {
test('Should do nothing if not animated', () => {
const isAnimate = jest.fn(() => false);
const isActivated = jest.fn(() => true);
const enter = jest.fn();
const component = { props: {}, isAnimate, isActivated, enter };
const flowManager = makeFlowManager(component);

flowManager.checkMount();
expect(enter).not.toHaveBeenCalled();
});

test('Should subscribe to parent node if parent is stream, animated', () => {
const isAnimate = jest.fn(() => true);
const isActivated = jest.fn(() => true);
const isOutsourced = jest.fn(() => true);
const _subscribe = jest.fn();
const component = {
props: { parentEnergyContext: { type: STREAM, _subscribe } },
isAnimate,
isActivated,
isOutsourced
isActivated
};
const flowManager = makeFlowManager(component);

flowManager.checkMount();
expect(_subscribe).toHaveBeenCalledWith(component);
});

test('Should do nothing if not animated', () => {
const isAnimate = jest.fn(() => false);
test('Should not subscribe to parent node if parent is stream, animated, and imperative', () => {
const isAnimate = jest.fn(() => true);
const isActivated = jest.fn(() => true);
const isOutsourced = jest.fn(() => false);
const enter = jest.fn();
const component = { props: {}, isAnimate, isActivated, isOutsourced, enter };
const _subscribe = jest.fn();
const component = {
props: { imperative: true, parentEnergyContext: { type: STREAM, _subscribe } },
isAnimate,
isActivated
};
const flowManager = makeFlowManager(component);

flowManager.checkMount();
expect(enter).not.toHaveBeenCalled();
expect(_subscribe).not.toHaveBeenCalledWith(component);
});

test('Should enter() if animated and activated', () => {
const isAnimate = jest.fn(() => true);
const isActivated = jest.fn(() => true);
const isOutsourced = jest.fn(() => false);
const enter = jest.fn();
const component = { props: {}, isAnimate, isActivated, isOutsourced, enter };
const component = { props: {}, isAnimate, isActivated, enter };
const flowManager = makeFlowManager(component);

flowManager.checkMount();
Expand Down Expand Up @@ -105,7 +116,7 @@ describe('checkUpdate()', () => {
});

describe('checkUnmount()', () => {
test('Should unsubscribe if parent node is stream and animated', () => {
test('Should unsubscribe if parent node is stream, animated', () => {
const isAnimate = jest.fn(() => true);
const _unsubscribe = jest.fn();
const component = {
Expand All @@ -117,4 +128,17 @@ describe('checkUnmount()', () => {
flowManager.checkUnmount();
expect(_unsubscribe).toHaveBeenCalledWith(component);
});

test('Should not unsubscribe if parent node is stream, animated, imperative', () => {
const isAnimate = jest.fn(() => true);
const _unsubscribe = jest.fn();
const component = {
props: { imperative: true, parentEnergyContext: { type: STREAM, _unsubscribe } },
isAnimate
};
const flowManager = makeFlowManager(component);

flowManager.checkUnmount();
expect(_unsubscribe).not.toHaveBeenCalledWith(component);
});
});

0 comments on commit 1e9a9f8

Please sign in to comment.