@searchspring/snap-controller 0.71.0 → 0.72.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +9 -69
  2. package/package.json +10 -10
package/README.md CHANGED
@@ -1,76 +1,16 @@
1
1
  # Snap Controller
2
2
 
3
- <a href="https://www.npmjs.com/package/@searchspring/snap-controller"><img alt="NPM Status" src="https://img.shields.io/npm/v/@searchspring/snap-controller.svg?style=flat"></a>
4
-
5
3
  The heart of controlling Search, Autocomplete, & Finder functionality. The Controller is responsible for tying various Snap services together.
6
4
 
5
+ Although `@searchspring/snap-controller` is published as a standalone package, it is not intended to be used directly. Internally it is a dependency of the `@searchspring/snap-preact` package.
7
6
 
8
- ## Dependencies
9
-
10
- Snap Controller is a top-level package that requires the following dependencies as services:
11
-
12
- <a href="https://www.npmjs.com/package/@searchspring/snap-client"><img alt="NPM Status" src="https://img.shields.io/npm/v/@searchspring/snap-client.svg?style=flat"></a> [@searchspring/snap-client](https://github.com/searchspring/snap/tree/main/packages/snap-client)
13
-
14
- <a href="https://www.npmjs.com/package/@searchspring/snap-store-mobx"><img alt="NPM Status" src="https://img.shields.io/npm/v/@searchspring/snap-store-mobx.svg?style=flat"></a> [@searchspring/snap-store-mobx](https://github.com/searchspring/snap/tree/main/packages/snap-store-mobx)
15
-
16
- <a href="https://www.npmjs.com/package/@searchspring/snap-url-manager"><img alt="NPM Status" src="https://img.shields.io/npm/v/@searchspring/snap-url-manager.svg?style=flat"></a> [@searchspring/snap-url-manager](https://github.com/searchspring/snap/tree/main/packages/snap-url-manager)
17
-
18
- <a href="https://www.npmjs.com/package/@searchspring/snap-event-manager"><img alt="NPM Status" src="https://img.shields.io/npm/v/@searchspring/snap-event-manager.svg?style=flat"></a> [@searchspring/snap-event-manager](https://github.com/searchspring/snap/tree/main/packages/snap-event-manager)
19
-
20
- <a href="https://www.npmjs.com/package/@searchspring/snap-profiler"><img alt="NPM Status" src="https://img.shields.io/npm/v/@searchspring/snap-profiler.svg?style=flat"></a> [@searchspring/snap-profiler](https://github.com/searchspring/snap/tree/main/packages/snap-profiler)
21
-
22
- <a href="https://www.npmjs.com/package/@searchspring/snap-logger"><img alt="NPM Status" src="https://img.shields.io/npm/v/@searchspring/snap-logger.svg?style=flat"></a> [@searchspring/snap-logger](https://github.com/searchspring/snap/tree/main/packages/snap-logger)
23
-
24
- ## Installation
25
-
26
- To install the `snap-controller` package and it's services:
27
-
28
- ```bash
29
- npm install --save @searchspring/snap-controller @searchspring/snap-client @searchspring/snap-store-mobx @searchspring/snap-url-manager @searchspring/snap-event-manager @searchspring/snap-profiler @searchspring/snap-logger
30
- ```
31
-
32
-
33
- ## Instantiation
34
- Each `Controller` must be passed a configuration object as the first parameter to the constructor, and a services object (dependencies) as the second. The contents of these objects will depend on which type of `Controller` is being instantiated. For example, a `SearchController` would usually be paired with a `SearchStore` service, and would take a `SearchControllerConfig` configuration object.
35
-
36
- The complete example below shows how a `SearchController` could be instatiated, initialized and searched:
37
-
38
- ```typescript
39
- import { Client } from '@searchspring/snap-client';
40
- import { SearchStore } from '@searchspring/snap-store-mobx';
41
- import { UrlManager, UrlTranslator } from '@searchspring/snap-url-manager';
42
- import { EventManager } from '@searchspring/snap-event-manager';
43
- import { Profiler } from '@searchspring/snap-profiler';
44
- import { Logger } from '@searchspring/snap-logger';
45
- import { Tracker } from '@searchspring/snap-tracker';
46
- import { SearchController } from '@searchspring/snap-controller';
47
-
48
- const configuration = {
49
- id: 'search'
50
- };
51
-
52
- const urlManager = new UrlManager(new UrlTranslator());
53
- const services = {
54
- client: new Client({ siteId: 'abc123' }),
55
- store: new SearchStore(configuration, { urlManager }),
56
- urlManager,
57
- eventManager: new EventManager(),
58
- profiler: new Profiler(),
59
- logger: new Logger(),
60
- tracker: new Tracker(),
61
- }
62
-
63
- const controller = new SearchController(configuration, services);
64
- controller.init();
65
- controller.search();
66
- ```
67
7
 
68
8
  ## Configuration
69
9
  The configuration object provided during instantiation provides a way of configuring the controller for different behavior. Each controller type (`SearchController`, `AutocompleteController`, `FinderController`, etc...) has default configurations that can be modified with the instantiation configuration object. At minimum an `id` attribute is required for identifying controllers. The `id` should be unique to each *instance* of a controller.
70
10
  ## Services
71
11
  Along with a configuration, each controller is passed a collection of services during instantiation. These services are then used by the controller and made available via controller methods. Sometimes controllers might share a reference to a service (the `client` service for example), but in most cases a controller will have it's own instance of a service. Some services (like the `SearchStore`) share services with the controller (in the example above, the `UrlManager` is shared).
72
12
 
73
- ```typescript
13
+ ```js
74
14
  { client, store, urlManager, eventManager, profiler, logger }
75
15
  ```
76
16
  ### client
@@ -94,7 +34,7 @@ The `logger` service provides logging functionality to a controller. Each contro
94
34
  Each Controller can optionally take a 3rd parameter for `Context`. This is to allow each individual controller to have its own individual context if so desired.
95
35
 
96
36
  The context is exposed as `controller.context`
97
- ```typescript
37
+ ```js
98
38
  controller.context;
99
39
  ```
100
40
 
@@ -102,7 +42,7 @@ controller.context;
102
42
  ## Initialization
103
43
  Invoking the `init` method is required to subscribe to changes that occur in the UrlManager. It also fires the `init` event which executes attached middleware. This can be fired manually as needed; if it was not manually fired it will happen automatically on the first call to the controller `search` method.
104
44
 
105
- ```typescript
45
+ ```js
106
46
  controller.init();
107
47
  ```
108
48
 
@@ -111,7 +51,7 @@ The `search` method of a controller will run the search that is expected by leve
111
51
 
112
52
  Most controllers will provide a means of manipulating the request and response using `beforeSearch` and `afterSearch` events respectively. Read on for details about events.
113
53
 
114
- ```typescript
54
+ ```js
115
55
  controller.search();
116
56
  ```
117
57
 
@@ -121,7 +61,7 @@ Different controller types will utilize different Snap Stores (typically of the
121
61
  ## Events
122
62
  Each controller will fire various events. Some of the event names are shared between controllers for consistency (ex: `beforeSearch`, `afterSearch`, `afterStore`); however the attaching of middleware and execution of it must remain separate. This is why a new `EventManager` instance is created for each controller. Middleware are attached to events via the `on` method and the functions should almost always end with `await next()` unless purposefully preventing the next attached middleware from executing.
123
63
 
124
- ```typescript
64
+ ```js
125
65
  controller.on('init', async (eventData, next) => {
126
66
  const { controller } = eventData;
127
67
 
@@ -135,7 +75,7 @@ Note: Groups of middleware (plugins) can be attached using the `plugin` method.
135
75
 
136
76
  The data available within a middleware (first parameter) is determined by what gets passed into the `fire` method. For existing events on the controller, the `fire` method is already being called when appropriate to the event, and the `eventData` will typically be an object containing a reference to the controller and any other details that may be of importance to the particular event. Custom events can be created as needed; but keep in mind that any middleware tied to the event should be bound (using `on` or `plugin`) prior to the execution of the `fire` method.
137
77
 
138
- ```typescript
78
+ ```js
139
79
  controller.eventManager.fire('customEventName', { thing1: 'one', thing2: 2 });
140
80
  ```
141
81
 
@@ -146,13 +86,13 @@ A controller's environment is initialized at build time, and is used to control
146
86
  ## Logging
147
87
  The logger provides a clear way of outputting details like profile data or errors to the developer console. A `production` build will supress most logs while a `development` build will show them all. The environment is automatically determined, but can be toggled during runtime by setting it to either `development` or `production`.
148
88
 
149
- ```typescript
89
+ ```js
150
90
  controller.environment = 'development';
151
91
  ```
152
92
 
153
93
  The use of `console.log()` is discouraged. Logging should be done via controller instance to help debug and navigate the sea of console logs. Each controller will output the `id` for easily deciphering which controller made the log.
154
94
 
155
- ```typescript
95
+ ```js
156
96
  controller.log.warn('THIS IS A WARNING!');
157
97
  ```
158
98
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@searchspring/snap-controller",
3
- "version": "0.71.0",
3
+ "version": "0.72.0",
4
4
  "description": "Snap Controllers",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -20,22 +20,22 @@
20
20
  "test:watch": "jest --watch"
21
21
  },
22
22
  "dependencies": {
23
- "@searchspring/snap-toolbox": "0.71.0",
23
+ "@searchspring/snap-toolbox": "0.72.0",
24
24
  "css.escape": "1.5.1",
25
25
  "deepmerge": "4.3.1"
26
26
  },
27
27
  "devDependencies": {
28
- "@searchspring/snap-client": "0.71.0",
29
- "@searchspring/snap-event-manager": "0.71.0",
30
- "@searchspring/snap-logger": "0.71.0",
31
- "@searchspring/snap-profiler": "0.71.0",
32
- "@searchspring/snap-store-mobx": "0.71.0",
33
- "@searchspring/snap-tracker": "0.71.0",
34
- "@searchspring/snap-url-manager": "0.71.0"
28
+ "@searchspring/snap-client": "0.72.0",
29
+ "@searchspring/snap-event-manager": "0.72.0",
30
+ "@searchspring/snap-logger": "0.72.0",
31
+ "@searchspring/snap-profiler": "0.72.0",
32
+ "@searchspring/snap-store-mobx": "0.72.0",
33
+ "@searchspring/snap-tracker": "0.72.0",
34
+ "@searchspring/snap-url-manager": "0.72.0"
35
35
  },
36
36
  "sideEffects": false,
37
37
  "files": [
38
38
  "dist/**/*"
39
39
  ],
40
- "gitHead": "86eb6dec8c57def5b869157dc00bbb9b6e793619"
40
+ "gitHead": "737d4bd308ebbb852fe3f09b2b90f4af87bbe264"
41
41
  }