Skip to content

Commit

Permalink
Bypass preprocessing states with no strings
Browse files Browse the repository at this point in the history
  • Loading branch information
bdowning committed Apr 20, 2016
1 parent 6f51b2e commit 3c264a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/preprocessors/tokenPreprocessor.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { identity } from '../index';

export function createTokenPreprocessor(options = { }) {
options = Object.assign({
defaultPrecision: 2
}, options);

return (state, easing) => {
const props = Object.keys(state).filter(k => typeof state[k] === 'string');

if (props.length === 0) {
return [ state, easing, identity ];
}

const newState = Object.assign({ }, state);
const newEasing = Object.assign({ }, easing);
const propsInfo = [ ];
Expand Down
6 changes: 3 additions & 3 deletions test/preprocessors/tokenPreprocessor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ describe('tokenPreprocessor', () => {
const [ outState, outEasing, decode ] =
tokenPreprocessor({ x: 1, y: 4 }, { x: identity, y: identity });

expect(outState).toEqual({ x: 1, y: 4 });
expect(outEasing).toEqual({ x: identity, y: identity });
expect(decode({ x: 3, y: 2 })).toEqual({ x: 3, y: 2 });
expect(outState).toBe(outState);
expect(outEasing).toBe(outEasing);
expect(decode).toBe(identity);
});

it('preprocesses and decodes simple stringified numbers', () => {
Expand Down

0 comments on commit 3c264a0

Please sign in to comment.