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

M major refactor #760

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
89ecac2
Composable selectors
Sep 26, 2017
5fca14d
Refactored the selector composing function into a utils class, added …
Oct 5, 2017
bf2f54e
Composable selectors
Sep 26, 2017
bc770f6
Convert existing selectors to dynamic dependency resolution
dahlbyk Oct 7, 2017
d2c97c8
Merge remote-tracking branch 'upstream/pr/743' into refactor-743
dahlbyk Oct 7, 2017
4089fad
Compose enhancers instead of overriding them
Sep 21, 2017
2c6e610
Roll back some changes
Oct 12, 2017
a04c699
Refactor and add story
Oct 12, 2017
0567dfc
Move selectors on context change to its own branch
Sep 18, 2017
8db33e1
Merge branch 'master' into m-composable-selectors
Oct 12, 2017
8f9c74c
add dataLoadingSelector to composedSelectors
Oct 12, 2017
ea0e50c
Small changes to TableContainer
Oct 12, 2017
6da06fa
Complete example story
Oct 12, 2017
8805225
Add actions to the context. Use the simple later plugins override met…
Oct 12, 2017
f37d2d0
Merge branch 'm-actions-on-context' into m-selectors-actions-on-context
Oct 12, 2017
983375d
Removed hard references to actions in the core code, deleted commente…
Oct 12, 2017
6366eaa
Merge branch 'refactor-743' into m-composable-selectors-refactor
Oct 13, 2017
f1fa4dd
First pass at moving 'core' code into a plugin. Stories seem to be wo…
Oct 13, 2017
1ce5b57
Most of the stuff associated with the 'core' plugin in src/index.js h…
Oct 16, 2017
b251237
Merge branch 'm-baseline-plugin' into m-major-refactor
Oct 17, 2017
02bc079
Merge branch 'm-composable-selectors-refactor' into m-major-refactor
Oct 17, 2017
334a68b
Merge branch 'm-selectors-actions-on-context' into m-major-refactor
Oct 17, 2017
2567ded
Merge branch 'm-composable-enhancers' into m-major-refactor
Oct 17, 2017
0d510aa
Updated store listener code to use the most current store state as it…
Oct 17, 2017
28cc4ff
Fixed core, local, and position plugin tests to work with new selecto…
Oct 19, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"typescript": "^2.4.1",
"webpack": "^1.14.0",
"webpack-dev-server": "^1.16.2",
"webpack-fail-plugin": "^1.0.6"
"webpack-fail-plugin": "^1.0.6",
"redux-logger": "^3.0.6"
},
"dependencies": {
"immutable": "^3.8.1",
Expand Down
13 changes: 0 additions & 13 deletions src/components/FilterContainer.js

This file was deleted.

13 changes: 0 additions & 13 deletions src/components/NextButtonContainer.js

This file was deleted.

12 changes: 0 additions & 12 deletions src/components/PreviousButtonContainer.js

This file was deleted.

22 changes: 0 additions & 22 deletions src/components/SettingsToggleContainer.js

This file was deleted.

28 changes: 0 additions & 28 deletions src/components/SettingsWrapperContainer.js

This file was deleted.

32 changes: 0 additions & 32 deletions src/components/TableContainer.js

This file was deleted.

121 changes: 55 additions & 66 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,26 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import _ from 'lodash';

import * as dataReducers from './reducers/dataReducer';
import components from './components';
//import * as dataReducers from './reducers/dataReducer';
//import components from './components';
import settingsComponentObjects from './settingsComponentObjects';
import * as selectors from './selectors/dataSelectors';
//import * as selectors from './selectors/dataSelectors';

import { buildGriddleReducer, buildGriddleComponents } from './utils/compositionUtils';
import { getColumnProperties } from './utils/columnUtils';
import { getRowProperties } from './utils/rowUtils';
//import { getColumnProperties } from './utils/columnUtils';
//import { getRowProperties } from './utils/rowUtils';
import { setSortProperties } from './utils/sortUtils';
import { StoreListener } from './utils/listenerUtils';
import * as actions from './actions';

const defaultEvents = {
...actions,
onFilter: actions.setFilter,
setSortProperties
};


const defaultStyleConfig = {
icons: {
TableHeadingCell: {
sortDescendingIcon: '▼',
sortAscendingIcon: '▲'
},
},
classNames: {
Cell: 'griddle-cell',
Filter: 'griddle-filter',
Loading: 'griddle-loadingResults',
NextButton: 'griddle-next-button',
NoResults: 'griddle-noResults',
PageDropdown: 'griddle-page-select',
Pagination: 'griddle-pagination',
PreviousButton: 'griddle-previous-button',
Row: 'griddle-row',
RowDefinition: 'griddle-row-definition',
Settings: 'griddle-settings',
SettingsToggle: 'griddle-settings-toggle',
Table: 'griddle-table',
TableBody: 'griddle-table-body',
TableHeading: 'griddle-table-heading',
TableHeadingCell: 'griddle-table-heading-cell',
TableHeadingCellAscending: 'griddle-heading-ascending',
TableHeadingCellDescending: 'griddle-heading-descending',
},
styles: {
}
};
import { composeSelectors } from './utils/selectorUtils';
//import * as actions from './actions';

import CorePlugin from './plugins/core';

//const defaultEvents = {
// ...actions,
// onFilter: actions.setFilter,
// setSortProperties
//};

class Griddle extends Component {
static childContextTypes = {
Expand All @@ -62,13 +33,15 @@ class Griddle extends Component {
events: PropTypes.object,
selectors: PropTypes.object,
storeKey: PropTypes.string,
storeListener: PropTypes.object
storeListener: PropTypes.object,
actions: PropTypes.object,
}

constructor(props) {
super(props);

const {
baselinePlugin=CorePlugin,
plugins=[],
data,
children:rowPropertiesComponent,
Expand All @@ -85,23 +58,40 @@ class Griddle extends Component {
...userInitialState
} = props;

const rowProperties = getRowProperties(rowPropertiesComponent);
const columnProperties = getColumnProperties(rowPropertiesComponent);
switch(typeof baselinePlugin) {
case 'function':
plugins.unshift(baselinePlugin(props));
break;
case 'object':
plugins.unshift(baselinePlugin);
break;
};

this.plugins = plugins;

//Combine / compose the reducers to make a single, unified reducer
const reducers = buildGriddleReducer([dataReducers, ...plugins.map(p => p.reducer)]);
//const reducers = buildGriddleReducer([dataReducers, ...plugins.map(p => p.reducer)]);
const reducers = buildGriddleReducer([...plugins.map(p => p.reducer)]);

//Combine / Compose the components to make a single component for each component type
this.components = buildGriddleComponents([components, ...plugins.map(p => p.components), userComponents]);
//this.components = buildGriddleComponents([components, ...plugins.map(p => p.components), userComponents]);
this.components = buildGriddleComponents([...plugins.map(p => p.components), userComponents]);

this.settingsComponentObjects = Object.assign({}, settingsComponentObjects, ...plugins.map(p => p.settingsComponentObjects), userSettingsComponentObjects);
// NOTE this goes on the context which for the purposes of breaking out the
// 'core' code into a plugin is somewhat of a problem as it should
// be associated with the core code not general griddle code.
this.settingsComponentObjects = Object.assign({}, ...plugins.map(p => p.settingsComponentObjects), userSettingsComponentObjects);

this.events = Object.assign({}, events, ...plugins.map(p => p.events));

this.selectors = plugins.reduce((combined, plugin) => ({ ...combined, ...plugin.selectors }), {...selectors});
this.selectors = composeSelectors(plugins);

this.actions = plugins.reduce((combined, plugin) => ({ ...combined, ...plugin.actions }), {});

const mergedStyleConfig = _.merge({}, defaultStyleConfig, ...plugins.map(p => p.styleConfig), styleConfig);
const mergedStyleConfig = _.merge({}, ...plugins.map(p => p.styleConfig), styleConfig);

// this would be good to move into the core plugin
// and namespace this state to the core plugin
const pageProperties = Object.assign({}, {
currentPage: 1,
pageSize: 10
Expand All @@ -110,21 +100,15 @@ class Griddle extends Component {
);

//TODO: This should also look at the default and plugin initial state objects
const renderProperties = Object.assign({
rowProperties,
columnProperties
}, ...plugins.map(p => p.renderProperties), userRenderProperties);
const renderProperties = Object.assign(...plugins.map(p => p.renderProperties), userRenderProperties);

// TODO: Make this its own method
// It would be nice if state was namespaced to the plugin
// it was associated with. For example pageProperties and
// sortProperties are specific to the core plugin. We could
// refactor the selectors to grab this data from a different
// place but would this affect other users?
const initialState = _.merge(
{
enableSettings: true,
textProperties: {
next: 'Next',
previous: 'Previous',
settingsToggle: 'Settings'
},
},
...plugins.map(p => p.initialState),
userInitialState,
{
Expand Down Expand Up @@ -161,8 +145,12 @@ class Griddle extends Component {
})

// Only update the state if something has changed.
//
// NOTE the update state reducer in 'core' griddle is only
// concerned with the data, pageProperties, and sortProperties
// passing in only changed props breaks the contract it is expecting
if (Object.keys(newState).length > 0) {
this.store.dispatch(actions.updateState(newState));
this.store.dispatch(this.plugins[0].actions.updateState(newState));
}
}

Expand All @@ -183,7 +171,8 @@ class Griddle extends Component {
events: this.events,
selectors: this.selectors,
storeKey: this.getStoreKey(),
storeListener: this.storeListener
storeListener: this.storeListener,
actions: this.actions,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ export namespace utils {
const compositionUtils: PropertyBag<Function>;
const dataUtils: PropertyBag<Function>;
const rowUtils: PropertyBag<Function>;
const selectorUtils: PropertyBag<Function>;

const connect : typeof originalConnect;

Expand Down
10 changes: 5 additions & 5 deletions src/module.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Griddle from './index';

import * as actions from './actions';
import components from './components';
import * as constants from './constants';
import * as selectors from './selectors/dataSelectors';
import * as actions from './plugins/core/actions';
import components from './plugins/core/components';
import * as constants from './plugins/core/constants';
import * as selectors from './plugins/core/selectors/dataSelectors';
import settingsComponentObjects from './settingsComponentObjects';
import utils from './utils';

Expand All @@ -14,7 +14,7 @@ import PositionPlugin from './plugins/position';
const plugins = {
LegacyStylePlugin,
LocalPlugin,
PositionPlugin,
PositionPlugin
};

const ColumnDefinition = components.ColumnDefinition;
Expand Down
File renamed without changes.
File renamed without changes.