Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Custom hooks - March 1 #75

Merged
merged 29 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9005923
Made DashRenderer standalone with hooks argument
valentijnnieman Sep 4, 2018
3fd37f5
Tests for DashRenderer with custom hooks
valentijnnieman Sep 4, 2018
89da3a2
Remove console.logs
valentijnnieman Sep 4, 2018
7e3045e
Add request and response parameters to hooks
valentijnnieman Sep 5, 2018
4af1751
Use dash-0.26.4 tarball for now
valentijnnieman Sep 7, 2018
e098366
Clean up DashRenderer class
valentijnnieman Sep 14, 2018
ed8350b
Remove JSON.Stringify() from request_pre payload parameter
valentijnnieman Sep 14, 2018
3564574
Replace typeof with Ramda's type
valentijnnieman Sep 14, 2018
26784c7
:zap: then()
valentijnnieman Sep 14, 2018
3b4d36f
Update type check for Ramda's type()
valentijnnieman Sep 20, 2018
f379521
Check if hooks are set or empty before hydrating
valentijnnieman Oct 3, 2018
ad6bcf0
Fire setHooks in AppContainer instead
valentijnnieman Oct 11, 2018
407062f
Cleanup
valentijnnieman Oct 12, 2018
458e143
Merge branch 'master' of https://github.com/plotly/dash-renderer into…
valentijnnieman Feb 15, 2019
9ab7ccc
Fixed tests with new Dash tar containing standalone dash-renderer
valentijnnieman Feb 15, 2019
7cb0fc5
Favour dash egg over tarball :egg
valentijnnieman Feb 15, 2019
8402201
Remove unneeded call_count from test
valentijnnieman Feb 15, 2019
bb91e78
Fix test with input clear() issue
valentijnnieman Feb 15, 2019
2d3ac1c
prettier & rebuild
alexcjohnson Feb 21, 2019
6c309d7
lint with both eslint and prettier
alexcjohnson Feb 21, 2019
86d5f62
Update test with payload param and add proptypes instead of type chec…
valentijnnieman Feb 27, 2019
c9e4386
Merge branch 'custom_hooks' of https://github.com/plotly/dash-rendere…
valentijnnieman Feb 27, 2019
fd3f4ab
Prettier fix
valentijnnieman Feb 27, 2019
d36daaa
Fire post before dispatches that use data.response
valentijnnieman Feb 27, 2019
d7c33d7
Update test with response data
valentijnnieman Feb 27, 2019
7bbfe5b
Fix formatting
valentijnnieman Feb 27, 2019
22b7275
Merge branch 'master' of https://github.com/plotly/dash-renderer into…
valentijnnieman Feb 28, 2019
a2cbcbe
Fix formatting
valentijnnieman Feb 28, 2019
aa6a365
Fix request hooks test
valentijnnieman Feb 28, 2019
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
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ jobs:
- "node_modules"

- run:
name: Npm lint
command: npm run lint
name: Prettier
command: npm run format:test
alexcjohnson marked this conversation as resolved.
Show resolved Hide resolved

- run:
name: Run tests
Expand Down Expand Up @@ -76,4 +76,4 @@ workflows:
jobs:
- "python-2.7"
- "python-3.6"
- "python-3.7"
- "python-3.7"
161 changes: 136 additions & 25 deletions dash_renderer/dash_renderer.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -33281,7 +33281,7 @@ var _Reloader = __webpack_require__(/*! ./components/core/Reloader.react */ "./s

var _Reloader2 = _interopRequireDefault(_Reloader);

var _actions = __webpack_require__(/*! ./actions */ "./src/actions/index.js");
var _index = __webpack_require__(/*! ./actions/index */ "./src/actions/index.js");

var _ramda = __webpack_require__(/*! ramda */ "./node_modules/ramda/index.js");

Expand All @@ -33296,18 +33296,23 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
var UnconnectedAppContainer = function (_React$Component) {
_inherits(UnconnectedAppContainer, _React$Component);

function UnconnectedAppContainer() {
function UnconnectedAppContainer(props) {
_classCallCheck(this, UnconnectedAppContainer);

return _possibleConstructorReturn(this, (UnconnectedAppContainer.__proto__ || Object.getPrototypeOf(UnconnectedAppContainer)).apply(this, arguments));
var _this = _possibleConstructorReturn(this, (UnconnectedAppContainer.__proto__ || Object.getPrototypeOf(UnconnectedAppContainer)).call(this, props));

if (props.hooks.request_pre !== null || props.hooks.request_post !== null) {
props.dispatch((0, _index.setHooks)(props.hooks));
}
return _this;
}

_createClass(UnconnectedAppContainer, [{
key: 'componentWillMount',
value: function componentWillMount() {
var dispatch = this.props.dispatch;

dispatch((0, _actions.readConfig)());
dispatch((0, _index.readConfig)());
}
}, {
key: 'render',
Expand Down Expand Up @@ -33337,6 +33342,7 @@ var UnconnectedAppContainer = function (_React$Component) {
}(_react2.default.Component);

UnconnectedAppContainer.propTypes = {
hooks: _propTypes2.default.object,
dispatch: _propTypes2.default.func,
config: _propTypes2.default.object
};
Expand Down Expand Up @@ -33382,22 +33388,78 @@ var _AppContainer = __webpack_require__(/*! ./AppContainer.react */ "./src/AppCo

var _AppContainer2 = _interopRequireDefault(_AppContainer);

var _propTypes = __webpack_require__(/*! prop-types */ "./node_modules/prop-types/index.js");

var _propTypes2 = _interopRequireDefault(_propTypes);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var store = (0, _store2.default)();

var AppProvider = function AppProvider() {
var AppProvider = function AppProvider(_ref) {
var hooks = _ref.hooks;

return _react2.default.createElement(
_reactRedux.Provider,
{ store: store },
_react2.default.createElement(_AppContainer2.default, null)
_react2.default.createElement(_AppContainer2.default, { hooks: hooks })
);
};

AppProvider.propTypes = {
hooks: _propTypes2.default.object
};

exports.default = AppProvider;

/***/ }),

/***/ "./src/DashRenderer.js":
/*!*****************************!*\
!*** ./src/DashRenderer.js ***!
\*****************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
/* eslint-env browser */



Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DashRenderer = undefined;

var _react = __webpack_require__(/*! react */ "react");

var _react2 = _interopRequireDefault(_react);

var _reactDom = __webpack_require__(/*! react-dom */ "react-dom");

var _reactDom2 = _interopRequireDefault(_reactDom);

var _AppProvider = __webpack_require__(/*! ./AppProvider.react */ "./src/AppProvider.react.js");

var _AppProvider2 = _interopRequireDefault(_AppProvider);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var DashRenderer = function DashRenderer() {
var hooks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { request_pre: null, request_post: null };

_classCallCheck(this, DashRenderer);

// render Dash Renderer upon initialising!
_reactDom2.default.render(_react2.default.createElement(_AppProvider2.default, { hooks: hooks }), document.getElementById('react-entry-point'));
};

exports.DashRenderer = DashRenderer;

/***/ }),

/***/ "./src/TreeContainer.js":
/*!******************************!*\
!*** ./src/TreeContainer.js ***!
Expand Down Expand Up @@ -33666,7 +33728,8 @@ var getAction = exports.getAction = function getAction(action) {
COMPUTE_PATHS: 'COMPUTE_PATHS',
SET_LAYOUT: 'SET_LAYOUT',
SET_APP_LIFECYCLE: 'SET_APP_LIFECYCLE',
READ_CONFIG: 'READ_CONFIG'
READ_CONFIG: 'READ_CONFIG',
SET_HOOKS: 'SET_HOOKS'
};
if (actionList[action]) {
return actionList[action];
Expand All @@ -33689,7 +33752,7 @@ var getAction = exports.getAction = function getAction(action) {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.readConfig = exports.setAppLifecycle = exports.setLayout = exports.computePaths = exports.computeGraphs = exports.setRequestQueue = exports.updateProps = undefined;
exports.setHooks = exports.readConfig = exports.setAppLifecycle = exports.setLayout = exports.computePaths = exports.computeGraphs = exports.setRequestQueue = exports.updateProps = undefined;

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); /* global fetch:true, Promise:true, document:true */

Expand Down Expand Up @@ -33729,6 +33792,7 @@ var computePaths = exports.computePaths = (0, _reduxActions.createAction)((0, _c
var setLayout = exports.setLayout = (0, _reduxActions.createAction)((0, _constants2.getAction)('SET_LAYOUT'));
var setAppLifecycle = exports.setAppLifecycle = (0, _reduxActions.createAction)((0, _constants2.getAction)('SET_APP_LIFECYCLE'));
var readConfig = exports.readConfig = (0, _reduxActions.createAction)((0, _constants2.getAction)('READ_CONFIG'));
var setHooks = exports.setHooks = (0, _reduxActions.createAction)((0, _constants2.getAction)('SET_HOOKS'));

function hydrateInitialOutputs() {
return function (dispatch, getState) {
Expand Down Expand Up @@ -34027,7 +34091,8 @@ function updateOutput(outputComponentId, outputProp, getState, requestUid, dispa
layout = _getState3.layout,
graphs = _getState3.graphs,
paths = _getState3.paths,
dependenciesRequest = _getState3.dependenciesRequest;
dependenciesRequest = _getState3.dependenciesRequest,
hooks = _getState3.hooks;

var InputGraph = graphs.InputGraph;

Expand Down Expand Up @@ -34080,6 +34145,16 @@ function updateOutput(outputComponentId, outputProp, getState, requestUid, dispa
});
}

if (hooks.request_pre !== null) {
if ((0, _ramda.type)(hooks.request_pre) === 'Function') {
hooks.request_pre(payload);
} else {
/* eslint-disable no-console */
// Throwing an Error or TypeError etc here will cause an infinite loop for some reason
console.error('The request_pre hook provided was not of type function, preventing Dash from firing it. Please make sure the request_pre hook is a function');
/* eslint-enable no-console */
}
}
return fetch((0, _utils2.urlBase)(config) + '_dash-update-component', {
method: 'POST',
headers: {
Expand Down Expand Up @@ -34186,6 +34261,18 @@ function updateOutput(outputComponentId, outputProp, getState, requestUid, dispa
props: data.response.props
}));

// Fire custom request_post hook if any
if (hooks.request_post !== null) {
if ((0, _ramda.type)(hooks.request_post) === 'Function') {
hooks.request_post(payload, data.response);
} else {
/* eslint-disable no-console */
// Throwing an Error or TypeError etc here will cause an infinite loop for some reason
console.error('The request_post hook provided was not of type function, preventing Dash from firing it. Please make sure the request_post hook is a function');
/* eslint-enable no-console */
}
}

/*
* If the response includes children, then we need to update our
* paths store.
Expand Down Expand Up @@ -34999,21 +35086,10 @@ var STATUS = exports.STATUS = {



var _react = __webpack_require__(/*! react */ "react");

var _react2 = _interopRequireDefault(_react);

var _reactDom = __webpack_require__(/*! react-dom */ "react-dom");

var _reactDom2 = _interopRequireDefault(_reactDom);

var _AppProvider = __webpack_require__(/*! ./AppProvider.react */ "./src/AppProvider.react.js");

var _AppProvider2 = _interopRequireDefault(_AppProvider);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _DashRenderer = __webpack_require__(/*! ./DashRenderer */ "./src/DashRenderer.js");

_reactDom2.default.render(_react2.default.createElement(_AppProvider2.default, null), document.getElementById('react-entry-point'));
// make DashRenderer globally available
window.DashRenderer = _DashRenderer.DashRenderer;

/***/ }),

Expand Down Expand Up @@ -35281,6 +35357,35 @@ exports.default = history;

/***/ }),

/***/ "./src/reducers/hooks.js":
/*!*******************************!*\
!*** ./src/reducers/hooks.js ***!
\*******************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";


Object.defineProperty(exports, "__esModule", {
value: true
});
var customHooks = function customHooks() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { request_pre: null, request_post: null, bear: false };
var action = arguments[1];

switch (action.type) {
case 'SET_HOOKS':
return action.payload;
default:
return state;
}
};

exports.default = customHooks;

/***/ }),

/***/ "./src/reducers/layout.js":
/*!********************************!*\
!*** ./src/reducers/layout.js ***!
Expand Down Expand Up @@ -35436,6 +35541,10 @@ var _history2 = __webpack_require__(/*! ./history */ "./src/reducers/history.js"

var _history3 = _interopRequireDefault(_history2);

var _hooks = __webpack_require__(/*! ./hooks */ "./src/reducers/hooks.js");

var _hooks2 = _interopRequireDefault(_hooks);

var _api = __webpack_require__(/*! ./api */ "./src/reducers/api.js");

var API = _interopRequireWildcard(_api);
Expand All @@ -35459,8 +35568,10 @@ var reducer = (0, _redux.combineReducers)({
config: _config3.default,
dependenciesRequest: API.dependenciesRequest,
layoutRequest: API.layoutRequest,
reloadRequest: API.reloadRequest,
history: _history3.default
loginRequest: API.loginRequest,
history: _history3.default,
hooks: _hooks2.default,
reloadRequest: API.reloadRequest
});

function getInputHistoryState(itempath, props, state) {
Expand Down
2 changes: 1 addition & 1 deletion dash_renderer/dash_renderer.dev.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dash_renderer/dash_renderer.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dash_renderer/dash_renderer.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
git+git://github.com/plotly/dash@master#egg=dash
git+git://github.com/plotly/dash@standalone_dash-renderer#egg=dash
percy
selenium
mock
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"build:dev": "webpack --mode development",
"build:prod": "webpack --mode production",
"start": "webpack-serve ./webpack.serve.config.js",
"format": "prettier --config .prettierrc --write src/**/*.js",
"format:test": "prettier --config .prettierrc src/**/*.js --list-different",
"format": "prettier --config .prettierrc --write src/**/*.js src/**/*.react.js",
"format:test": "prettier --config .prettierrc src/**/*.js src/**/*.react.js --list-different",
"test": "npm run lint",
"test:py": "python -m unittest tests.test_render tests.test_race_conditions"
},
Expand Down
15 changes: 12 additions & 3 deletions src/AppContainer.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ import DocumentTitle from './components/core/DocumentTitle.react';
import Loading from './components/core/Loading.react';
import Toolbar from './components/core/Toolbar.react';
import Reloader from './components/core/Reloader.react';
import {readConfig} from './actions';
import {setHooks, readConfig} from './actions/index';
import {type} from 'ramda';


class UnconnectedAppContainer extends React.Component {
constructor(props) {
super(props);
if (
props.hooks.request_pre !== null ||
props.hooks.request_post !== null
) {
props.dispatch(setHooks(props.hooks));
}
}

componentWillMount() {
const {dispatch} = this.props;
dispatch(readConfig())
dispatch(readConfig());
}

render() {
Expand All @@ -35,6 +43,7 @@ class UnconnectedAppContainer extends React.Component {
}

UnconnectedAppContainer.propTypes = {
hooks: PropTypes.object,
dispatch: PropTypes.func,
config: PropTypes.object,
};
Expand Down
18 changes: 13 additions & 5 deletions src/AppProvider.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ import {Provider} from 'react-redux';
import initializeStore from './store';
import AppContainer from './AppContainer.react';

import PropTypes from 'prop-types';

const store = initializeStore();

const AppProvider = () => (
<Provider store={store}>
<AppContainer />
</Provider>
);
const AppProvider = ({hooks}) => {
return (
<Provider store={store}>
<AppContainer hooks={hooks} />
</Provider>
);
};

AppProvider.propTypes = {
hooks: PropTypes.object,
};

export default AppProvider;
19 changes: 19 additions & 0 deletions src/DashRenderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-env browser */

'use strict';

import React from 'react';
import ReactDOM from 'react-dom';
import AppProvider from './AppProvider.react';

class DashRenderer {
constructor(hooks = { request_pre: null, request_post: null}) {
// render Dash Renderer upon initialising!
ReactDOM.render(
<AppProvider hooks={hooks} />,
document.getElementById('react-entry-point')
);
}
}

export { DashRenderer };
Loading