Skip to content

Commit 633008e

Browse files
committed
Cleanup
1 parent b5ad33c commit 633008e

File tree

4 files changed

+51
-21
lines changed

4 files changed

+51
-21
lines changed

src/app-search/AppSearchDriver.js

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,31 @@ const DEFAULT_STATE = {
4141
* The Driver is a framework agnostic state manager for App Search apps. Meaning,
4242
* it is the source of truth for state in this React App, but it has no
4343
* dependencies on React itself.
44+
*
45+
* The public interface of the Driver can be thought about in the following
46+
* way:
47+
*
48+
* Ways to GET state:
49+
* - getState - Get the initial app state
50+
* - subscribeToStateChanges - Get updated state whenever it changes
51+
*
52+
* Ways to SET state, or "Actions" as we refer to them elsewhere
53+
* - addFilter, etc, will typically update the state and trigger new queries
54+
*
4455
*/
4556
export default class AppSearchDriver {
4657
state = DEFAULT_STATE;
4758

4859
/**
4960
*
50-
* @param options {*}
51-
*
61+
* @param options Object
5262
* engineName - Engine to query, found in your App Search Dashboard
5363
* hostIdentifier - Credential found in your App Search Dashboard
54-
* initialState - This lets you set initial search parameters
64+
* initialState - This lets you set initial search parameters, ex:
65+
* `searchTerm: "test"`
5566
* searchKey - Credential found in your App Search Dashboard
56-
* searchOptions - A low level configuration which let's you configure
57-
* the options used on the Search API endpoint
67+
* searchOptions - A low level configuration which lets you configure
68+
* the options used on the Search API endpoint, ex: `result_fields`
5869
*/
5970
constructor({
6071
engineName,
@@ -76,10 +87,11 @@ export default class AppSearchDriver {
7687
this.URLManager.onURLStateChange(urlState => {
7788
this._updateSearchResults({ ...DEFAULT_STATE, ...urlState }, true);
7889
});
79-
// We filter these here, because the only state that should be allowed
80-
// to be passed in, is search parameter state. Results, etc, should not
81-
// be allowed to be passed in, that should be generated based on the
82-
// provided search parameters.
90+
91+
// We filter these here to disallow anything other than valid search
92+
// parameters to be passed in initial state, or url state. `results`, etc,
93+
// should not be allowed to be passed in, that should be generated based on
94+
// the results of the query
8395
const searchParameters = filterSearchParameters({
8496
...this.state,
8597
...initialState,
@@ -88,15 +100,15 @@ export default class AppSearchDriver {
88100

89101
// Initialize the state without calling _setState, because we don't
90102
// want to trigger an update callback, we're just initializing the state
91-
// to the correct default values.
103+
// to the correct default values for the initial UI render
92104
this.state = {
93105
...this.state,
94106
...searchParameters
95107
};
96108

97-
// We'll trigger an initial search if initial parameters contains
109+
// We'll trigger an initial search if initial parameters contain
98110
// a search term or filters, otherwise, we'll just save their selections
99-
// in state as defaults.
111+
// in state as initial values.
100112
if (searchParameters.searchTerm || searchParameters.filters.length > 0) {
101113
this._updateSearchResults(searchParameters);
102114
}
@@ -310,6 +322,13 @@ export default class AppSearchDriver {
310322
});
311323
};
312324

325+
/**
326+
* Set the current page
327+
*
328+
* Will trigger new search
329+
*
330+
* @param current Integer
331+
*/
313332
setCurrent = current => {
314333
const {
315334
filters,

src/app-search/AppSearchProvider.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ import AppSearchContext from "./AppSearchContext";
55

66
/**
77
* The AppSearchProvider is the glue that connects the AppSearchDriver to
8-
* our React App. It "subscribes" to the driver in order to be
9-
* notified of state updates, and then passes that state down to child
10-
* components in a React Context. It will also pass down "actions" from the
11-
* AppSearchDriver, which allow child components to update state.
8+
* our React App.
9+
*
10+
* It "subscribes" to the AppSearchDriver in order to be notified of state
11+
* changes. It then syncs that state with its own state and passes that state
12+
* down to child components in a React Context. It will also pass down "Actions"
13+
* from the AppSearchDriver, which allow child components to update state.
14+
*
15+
* Any "Container" component placed within this context will have access
16+
* to the Driver's state and Actions.
17+
*
1218
*/
1319
class AppSearchProvider extends Component {
1420
static propTypes = {
@@ -45,7 +51,7 @@ class AppSearchProvider extends Component {
4551
searchTerm,
4652
sortDirection,
4753
sortField,
48-
// Result data
54+
// Result State
4955
facets,
5056
requestId,
5157
results,

src/app-search/withAppSearch.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import React from "react";
22

33
import AppSearchConsumer from "../app-search/AppSearchConsumer";
44

5+
/**
6+
* This is a Higher Order Component that is used to expose (as `props`) all
7+
* state and Actions provided by the AppSearchProvider to "container"
8+
* components.
9+
*/
510
export default function withAppSearch(Component) {
611
return function(props) {
712
return (

src/config/config-helper.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { create } from "../types/SortOption";
44
/**
55
* This file abstracts most logic around the configuration of the Reference UI.
66
*
7-
* Configuration is an important part of the "reusability" and "genericness" of the
8-
* Reference UI, but if you are using this app as a starting point for own
9-
* project, everything related to configuration can largely be thrown away. To that
10-
* end, this file attempts to contain most of that logic to one place.
7+
* Configuration is an important part of the "reusability" and "generic-ness" of
8+
* the Reference UI, but if you are using this app as a starting point for own
9+
* project, everything related to configuration can largely be thrown away. To
10+
* that end, this file attempts to contain most of that logic to one place.
1111
*/
1212

1313
export function getConfig() {

0 commit comments

Comments
 (0)