Skip to content

Commit

Permalink
refactor(theme): optimize module imports (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
artyorsh authored Jan 3, 2019
1 parent cd60eb2 commit 2c86a03
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 54 deletions.
5 changes: 3 additions & 2 deletions src/framework/theme/component/mapping/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './type';
export * from './mappingContext';
export {
MappingProvider as ThemeMappingProvider,
Props as ThemeMappingProviderProps,
MappingProvider,
Props as MappingProviderProps,
} from './mappingProvider.component';
3 changes: 1 addition & 2 deletions src/framework/theme/component/mapping/mappingContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ import React from 'react';
import { ThemeMappingType } from './type';

const defaultValue: ThemeMappingType = {};
const MappingContext = React.createContext(defaultValue);

export default MappingContext;
export const MappingContext = React.createContext(defaultValue);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import MappingContext from './mappingContext';
import { MappingContext } from './mappingContext';
import { ThemeMappingType } from './type';

export interface Props {
Expand Down
3 changes: 1 addition & 2 deletions src/framework/theme/component/style/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './type';
export {
StyleProvider,
Props as StyleProviderProps,
Expand All @@ -7,5 +8,3 @@ export {
styled,
Props as StyledComponentProps,
} from './styleConsumer.component';

export * from './type';
18 changes: 9 additions & 9 deletions src/framework/theme/component/style/styleConsumer.component.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
import { ThemeMappingType } from '../mapping';
import {
ThemeType,
StyleType,
} from '../theme';
import ThemeContext from '../theme/themeContext';
import MappingContext from '../mapping/mappingContext';
import { MappingContext } from '../mapping';
import { ThemeContext } from '../theme';
import { getComponentMapping } from '../../service/mapping';
import {
createStyle,
StyleConsumerService,
} from '../../service/style';
import { getComponentMapping } from '../../service/mapping';
import { Interaction } from './type';
import {
ThemeMappingType,
ThemeType,
StyleType,
Interaction,
} from '../../component';

interface PrivateProps<T> {
forwardedRef: React.RefObject<T>;
Expand Down
20 changes: 9 additions & 11 deletions src/framework/theme/component/style/styleProvider.component.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import React from 'react';
import {
MappingProvider,
MappingProviderProps,
ThemeMappingType,
} from '../mapping';
import {
ThemeProvider,
ThemeProviderProps,
ThemeType,
} from '../theme';
import {
ThemeMappingProvider,
ThemeMappingType,
} from '../mapping';

export interface Props {
mapping: ThemeMappingType;
theme: ThemeType;
children: JSX.Element | React.ReactNode;
}
export type Props = MappingProviderProps & ThemeProviderProps;

interface State {
mapping: ThemeMappingType;
Expand All @@ -35,11 +33,11 @@ export class StyleProvider extends React.Component<Props, State> {

render() {
return (
<ThemeMappingProvider mapping={this.state.mapping}>
<MappingProvider mapping={this.state.mapping}>
<ThemeProvider theme={this.state.theme}>
{this.props.children}
</ThemeProvider>
</ThemeMappingProvider>
</MappingProvider>
);
}
}
1 change: 1 addition & 0 deletions src/framework/theme/component/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './type';
export * from './themeContext';
export {
ThemeProvider,
Props as ThemeProviderProps,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
import ThemeContext from './themeContext';
import { ThemeContext } from './themeContext';
import {
ThemeType,
ThemedStyleType,
Expand Down
3 changes: 1 addition & 2 deletions src/framework/theme/component/theme/themeContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ import React from 'react';
import { ThemeType } from './type';

const defaultValue: ThemeType = {};
const ThemeContext = React.createContext(defaultValue);

export default ThemeContext;
export const ThemeContext = React.createContext(defaultValue);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ReactNode } from 'react';
import ThemeContext from './themeContext';
import { ThemeContext } from './themeContext';
import { ThemeType } from './type';

export interface Props {
Expand Down
2 changes: 1 addition & 1 deletion src/framework/theme/service/style/style.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getStatelessVariantMapping,
getStateAppearanceMapping,
getStateVariantMapping,
} from '../mapping/mapping.service';
} from '../mapping';
import {
ComponentMappingType,
ThemeType,
Expand Down
39 changes: 18 additions & 21 deletions src/framework/theme/service/style/style.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { APPEARANCE_DEFAULT } from '../mapping';
import {
mapping,
theme,
} from './style.spec.config';
import * as Service from './style.service';
import * as config from './style.spec.config';

describe('@style: service methods checks', () => {

const { Test: testMapping } = mapping;
const { Test: testMapping } = config.mapping;

describe('* preprocess', () => {

Expand Down Expand Up @@ -149,15 +146,15 @@ describe('@style: service methods checks', () => {
describe('* default appearance', () => {

it('* no variant and no state', () => {
const style = Service.createStyle(theme, testMapping);
const style = Service.createStyle(config.theme, testMapping);
expect(style).toMatchSnapshot();
});

describe('* with state', () => {

it('* single', () => {
const style = Service.createStyle(
theme,
config.theme,
testMapping,
APPEARANCE_DEFAULT,
[],
Expand All @@ -169,7 +166,7 @@ describe('@style: service methods checks', () => {

it('* multiple', () => {
const style = Service.createStyle(
theme,
config.theme,
testMapping,
APPEARANCE_DEFAULT,
[],
Expand All @@ -186,7 +183,7 @@ describe('@style: service methods checks', () => {

it('* no state', () => {
const style = Service.createStyle(
theme,
config.theme,
testMapping,
APPEARANCE_DEFAULT,
['success'],
Expand All @@ -199,7 +196,7 @@ describe('@style: service methods checks', () => {

it('* single implicit (should apply from appearance)', () => {
const style = Service.createStyle(
theme,
config.theme,
testMapping,
APPEARANCE_DEFAULT,
['success'],
Expand All @@ -211,7 +208,7 @@ describe('@style: service methods checks', () => {

it('* single explicit (should apply own)', () => {
const style = Service.createStyle(
theme,
config.theme,
testMapping,
APPEARANCE_DEFAULT,
['success'],
Expand All @@ -223,7 +220,7 @@ describe('@style: service methods checks', () => {

it('* multiple', () => {
const style = Service.createStyle(
theme,
config.theme,
testMapping,
APPEARANCE_DEFAULT,
['success'],
Expand All @@ -241,7 +238,7 @@ describe('@style: service methods checks', () => {

it('* no state', () => {
const style = Service.createStyle(
theme,
config.theme,
testMapping,
APPEARANCE_DEFAULT,
['success', 'big'],
Expand All @@ -254,7 +251,7 @@ describe('@style: service methods checks', () => {

it('* single', () => {
const style = Service.createStyle(
theme,
config.theme,
testMapping,
APPEARANCE_DEFAULT,
['success', 'big'],
Expand All @@ -266,7 +263,7 @@ describe('@style: service methods checks', () => {

it('* multiple', () => {
const style = Service.createStyle(
theme,
config.theme,
testMapping,
APPEARANCE_DEFAULT,
['success', 'big'],
Expand All @@ -287,7 +284,7 @@ describe('@style: service methods checks', () => {
describe('* custom appearance', () => {

it('* no variant and no state', () => {
const style = Service.createStyle(theme, testMapping, 'custom');
const style = Service.createStyle(config.theme, testMapping, 'custom');

expect(style).toMatchSnapshot();
});
Expand All @@ -296,7 +293,7 @@ describe('@style: service methods checks', () => {

it('* implicit (should apply from default appearance)', () => {
const style = Service.createStyle(
theme,
config.theme,
testMapping,
'custom',
[],
Expand All @@ -308,7 +305,7 @@ describe('@style: service methods checks', () => {

it('* explicit (should apply own)', () => {
const style = Service.createStyle(
theme,
config.theme,
testMapping,
'custom',
[],
Expand All @@ -324,7 +321,7 @@ describe('@style: service methods checks', () => {

it('* implicit (should apply from default appearance)', () => {
const style = Service.createStyle(
theme,
config.theme,
testMapping,
'custom',
['big'],
Expand All @@ -335,7 +332,7 @@ describe('@style: service methods checks', () => {

it('* explicit (should apply own)', () => {
const style = Service.createStyle(
theme,
config.theme,
testMapping,
'custom',
['success'],
Expand All @@ -351,7 +348,7 @@ describe('@style: service methods checks', () => {
describe('* undefined appearance', () => {

it('* no variant and no state (should apply default appearance)', () => {
const style = Service.createStyle(theme, testMapping, 'undefined');
const style = Service.createStyle(config.theme, testMapping, 'undefined');

expect(style).toMatchSnapshot();
});
Expand Down
2 changes: 1 addition & 1 deletion src/framework/theme/service/style/styleConsumer.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
Interaction,
State,
} from '../../component';
import { APPEARANCE_DEFAULT } from '../mapping/mapping.service';
import { APPEARANCE_DEFAULT } from '../mapping';
import { StyleConsumerService } from './styleConsumer.service';
import {
mapping,
Expand Down

0 comments on commit 2c86a03

Please sign in to comment.