Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(griffith-utils): rename mergeFunctions to sequence #41

Merged
merged 1 commit into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions packages/griffith-utils/src/__tests__/mergeFunctions.spec.js

This file was deleted.

9 changes: 9 additions & 0 deletions packages/griffith-utils/src/__tests__/sequence.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sequence from '../sequence'

test('sequence', () => {
const fn1 = jest.fn(() => 1)
const fn2 = jest.fn(() => 2)
expect(sequence(fn1, fn2)('foo', 'bar')).toBe(2)
expect(fn1).toHaveBeenCalledWith('foo', 'bar')
expect(fn2).toHaveBeenCalledWith('foo', 'bar')
})
2 changes: 1 addition & 1 deletion packages/griffith-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export {default as ua} from './ua'
export {default as isMSESupported} from './isMSESupported'
export {default as isHlsNativeSupported} from './isHlsNativeSupported'
export {getGCD, reduce} from './math'
export {default as mergeFunctions} from './mergeFunctions'
export {default as sequence} from './sequence'
6 changes: 0 additions & 6 deletions packages/griffith-utils/src/mergeFunctions.js

This file was deleted.

3 changes: 3 additions & 0 deletions packages/griffith-utils/src/sequence.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function sequence(...fns) {
return (...args) => fns.reduce((_, fn) => fn(...args), null)
}
7 changes: 4 additions & 3 deletions packages/griffith/src/components/Hover/Hover.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import {mergeFunctions} from 'griffith-utils'
import {sequence} from 'griffith-utils'
import noop from 'lodash/noop'

export default class Hover extends React.Component {
state = {
Expand All @@ -20,8 +21,8 @@ export default class Hover extends React.Component {
return (
<div
{...rest}
onMouseEnter={mergeFunctions(this.handlePointerEnter, onMouseEnter)}
onMouseLeave={mergeFunctions(this.handlePointerLeave, onMouseLeave)}
onMouseEnter={sequence(this.handlePointerEnter, onMouseEnter || noop)}
onMouseLeave={sequence(this.handlePointerLeave, onMouseLeave || noop)}
>
{children(isHovered)}
</div>
Expand Down
10 changes: 5 additions & 5 deletions packages/griffith/src/components/Video/VideoWithMessage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import {EVENTS} from 'griffith-message'
import mergeFunctions from 'griffith-utils/src/mergeFunctions'

import {sequence} from 'griffith-utils'
import noop from 'lodash/noop'
import {InternalContext} from '../../contexts/Message'
import {ObjectFitContext} from '../../contexts/ObjectFit'
import {PositionContext} from '../../contexts/Position'
Expand Down Expand Up @@ -37,7 +37,7 @@ const VideoWithMessage = React.forwardRef((props, ref) => {
eventMap.map(([eventName, key]) => {
const handler = props[key]
const emit = event => emitEvent(eventName, getMediaEventPayload(event))
newProps[key] = mergeFunctions(emit, handler)
newProps[key] = sequence(emit, handler || noop)
})

const updateVideoSizeOnLoadedMetadata = event => {
Expand All @@ -48,9 +48,9 @@ const VideoWithMessage = React.forwardRef((props, ref) => {
}
}

const newOnLoadedMetadata = mergeFunctions(
const newOnLoadedMetadata = sequence(
updateVideoSizeOnLoadedMetadata,
props.onLoadedMetadata
props.onLoadedMetadata || noop
)

const {Video, ...otherProps} = props
Expand Down