Skip to content
Snippets Groups Projects
Commit cca55fcf authored by Jack Reed's avatar Jack Reed
Browse files

add basic jsdoc requirement for project

parent 90d57b4b
Branches
Tags
No related merge requests found
......@@ -9,6 +9,15 @@
},
"plugins": ["jest"],
"rules": {
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }]
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true,
"ArrowFunctionExpression": true,
"FunctionExpression": true,
}
}]
}
}
import fetch from 'node-fetch';
import ActionTypes from '../action-types';
/*
* Action creators
/**
* Action Creators for Mirador
* @namespace ActionCreators
*/
/**
* focusWindow - action creator
*
* @param {String} windowId
* @memberof ActionCreators
*/
export function focusWindow(windowId) {
return { type: ActionTypes.FOCUS_WINDOW, windowId };
}
/**
* addWindow - action creator
*
* @param {Object} options
* @memberof ActionCreators
*/
export function addWindow(options) {
const defaultOptions = {
// TODO: Windows should be a hash with id's as keys for easy lookups
......@@ -24,18 +37,42 @@ export function addWindow(options) {
return { type: ActionTypes.ADD_WINDOW, payload: Object.assign({}, defaultOptions, options) };
}
/**
* removeWindow - action creator
*
* @param {String} windowId
* @memberof ActionCreators
*/
export function removeWindow(windowId) {
return { type: ActionTypes.REMOVE_WINDOW, windowId };
}
/**
* nextCanvas - action creator
*
* @param {String} windowId
* @memberof ActionCreators
*/
export function nextCanvas(windowId) {
return { type: ActionTypes.NEXT_CANVAS, windowId };
}
/**
* previousCanvas - action creator
*
* @param {String} windowId
* @memberof ActionCreators
*/
export function previousCanvas(windowId) {
return { type: ActionTypes.PREVIOUS_CANVAS, windowId };
}
/**
* requestManifest - action creator
*
* @param {String} manifestId
* @memberof ActionCreators
*/
export function requestManifest(manifestId) {
return {
type: ActionTypes.REQUEST_MANIFEST,
......@@ -43,6 +80,13 @@ export function requestManifest(manifestId) {
};
}
/**
* receiveManifest - action creator
*
* @param {String} windowId
* @param {Object} manifestJson
* @memberof ActionCreators
*/
export function receiveManifest(manifestId, manifestJson) {
return {
type: ActionTypes.RECEIVE_MANIFEST,
......@@ -51,6 +95,13 @@ export function receiveManifest(manifestId, manifestJson) {
};
}
/**
* receiveManifestFailure - action creator
*
* @param {String} windowId
* @param {String} error
* @memberof ActionCreators
*/
export function receiveManifestFailure(manifestId, error) {
return {
type: ActionTypes.RECEIVE_MANIFEST_FAILURE,
......@@ -59,6 +110,12 @@ export function receiveManifestFailure(manifestId, error) {
};
}
/**
* fetchManifest - action creator
*
* @param {String} manifestId
* @memberof ActionCreators
*/
export function fetchManifest(manifestId) {
return ((dispatch) => {
dispatch(requestManifest(manifestId));
......
......
......@@ -5,7 +5,14 @@ import { actions } from '../store';
import Display from './Display';
import ManifestForm from './ManifestForm';
/**
* This is the top level Mirador component.
* @prop {Object} manifests
*/
class App extends Component {
/**
* constructor -
*/
constructor(props) {
super(props);
this.state = {
......@@ -15,12 +22,23 @@ class App extends Component {
this.setLastRequested = this.setLastRequested.bind(this);
}
/**
* setLastRequested - Sets the state lastRequested
*
* @private
*/
setLastRequested(requested) {
this.setState({
lastRequested: requested,
});
}
/**
* computedContent - computes the content to be displayed based on logic
*
* @return {type} description
* @private
*/
computedContent() {
const manifest = this.props.manifests[this.state.lastRequested];
if (manifest) {
......@@ -34,6 +52,10 @@ class App extends Component {
return 'Nothing Selected Yet';
}
/**
* render
* @return {String} - HTML markup for the component
*/
render() {
const manifestList = Object.keys(this.props.manifests).map(manifest => (
<li key={manifest}>{manifest}</li>
......@@ -55,12 +77,22 @@ App.propTypes = {
manifests: PropTypes.instanceOf(Object).isRequired,
};
/**
* mapStateToProps - to hook up connect
* @memberof App
* @private
*/
const mapStateToProps = state => (
{
manifests: state.manifests,
}
);
/**
* mapDispatchToProps - used to hook up connect to action creators
* @memberof App
* @private
*/
const mapDispatchToProps = dispatch => ({
fetchManifest: manifestUrl => (
dispatch(actions.fetchManifest(manifestUrl))
......
......
import React from 'react';
import PropTypes from 'prop-types';
/**
* Determines how to best display the content (or lack thereof) the manifest
* @private
*/
const displayContent = (manifest) => {
if (manifest) {
if (manifest.isFetching) {
......@@ -13,6 +18,12 @@ const displayContent = (manifest) => {
return 'Nothing Selected Yet';
};
/**
* Determines which classes should be used for display, based on the state of
* the manifest
* @memberof Display
* @private
*/
const stateClass = (manifest) => {
if (manifest) {
if (manifest.isFetching) {
......@@ -25,10 +36,16 @@ const stateClass = (manifest) => {
return 'empty';
};
const Display = props => (
/**
* Displays a manifest
* @param {object} props
* @param {object} [props.manifest = undefined]
*/
const Display = ({ manifest }) => (
<div className="Display">
<pre id="exampleManifest" className={stateClass(props.manifest)}>
{displayContent(props.manifest)}
<pre id="exampleManifest" className={stateClass(manifest)}>
{displayContent(manifest)}
</pre>
</div>
);
......
......
......@@ -3,7 +3,15 @@ import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { actions } from '../store';
/**
* Provides a form for user input of a manifest url
* @prop {Function} fetchManifest
* @prop {Function} setLastRequested
*/
class ManifestForm extends Component {
/**
* constructor -
*/
constructor(props) {
super(props);
this.state = {
......@@ -14,12 +22,22 @@ class ManifestForm extends Component {
this.handleInputChange = this.handleInputChange.bind(this);
}
/**
* formSubmit - triggers manifest update and sets lastRequested
* @param {Event} event
* @private
*/
formSubmit(event) {
event.preventDefault();
this.props.fetchManifest(this.state.formValue);
this.props.setLastRequested(this.state.formValue);
}
/**
* handleInputChange - sets state based on input change.
* @param {Event} event
* @private
*/
handleInputChange(event) {
const that = this;
event.preventDefault();
......@@ -28,7 +46,10 @@ class ManifestForm extends Component {
});
}
/**
* render
* @return {String} - HTML markup for the component
*/
render() {
return (
<form onSubmit={this.formSubmit}>
......@@ -49,11 +70,20 @@ ManifestForm.propTypes = {
setLastRequested: PropTypes.func.isRequired,
};
/**
* mapStateToProps - to hook up connect
* @memberof ManifestForm
* @private
*/
const mapStateToProps = () => (
{}
);
/**
* mapDispatchToProps - used to hook up connect to action creators
* @memberof ManifestForm
* @private
*/
const mapDispatchToProps = dispatch => ({
fetchManifest: manifestUrl => (
dispatch(actions.fetchManifest(manifestUrl))
......
......
......@@ -4,16 +4,8 @@ import windowsReducer from './windows';
import manifestsReducer from './manifests';
/**
* This is a reducer, a pure function with (state, action) => state signature.
* It describes how an action transforms the state into the next state.
*
* The shape of the state is up to you: it can be a primitive, an array, an object,
* or even an Immutable.js data structure. The only important part is that you should
* not mutate the state object, but return a new object if the state changes.
*
* In this example, we use a `switch` statement and strings, but you can use a helper that
* follows a different convention (such as function maps) if it makes sense for your
* project.
* Action Creators for Mirador
* @namespace RootReducer
*/
const rootReducer = combineReducers({
......
......
import ActionTypes from '../action-types';
/**
* manifestsReducer
*/
const manifestsReducer = (state = {}, action) => {
switch (action.type) {
case ActionTypes.REQUEST_MANIFEST:
......
......
import ActionTypes from '../action-types';
/**
* windowsReducer
*/
const windowsReducer = (state = [], action) => {
switch (action.type) {
case ActionTypes.ADD_WINDOW:
......
......
import ActionTypes from '../action-types';
/**
* workspaceReducer
*/
const workspaceReducer = (state = {}, action) => {
switch (action.type) {
case ActionTypes.FOCUS_WINDOW:
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment