skandha 0.10.1 → 0.10.2

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.
package/README.md CHANGED
@@ -1,8 +1,31 @@
1
1
  # SkandhaJS
2
2
 
3
- ## Rationale
3
+ ## Introduction
4
4
 
5
- The goal of SkandhaJS is to provide data containers that have reusable behaviors, such as selection, highlighting, filtering, drag-and-drop, etc. The only requirement for using these containers is that every item in the container has a unique id. SkandhaJS allows you to combine behaviors and make them interact properly. For example, when selecting an item you may want the item also to be highlighted. As we will see, these interactions are achieved by implementing callback functions.
5
+ The goal of SkandhaJS is to provide data containers that have reusable behaviors. These behaviours are implemented in classes called "facets". Examples of facets are selection, highlighting, filtering, drag-and-drop, etc. By connecting these facets, you can create interactions between different behaviours.
6
+
7
+ Every facet provides an interface that supports a particular behaviour. This interface is used throughout the application, and ensures that the basic mechanism (e.g. for doing selection) is the same everywhere. The details of the behaviour depend on callback functions that the programmer provides:
8
+
9
+ 1. Callbacks decide what exactly happens when an item is selected, highlighted, deleted etc.
10
+ 2. Callbacks implement interactions. For example: when selecting an item, also higlight it.
11
+
12
+ The second point is important for limiting the mixing of concerns that happens when you are combining multiple behaviours. This mixing of concerns is unavoidable, but should be limited to specific places that can be easily inspected.
13
+
14
+ As a brief illustration, consider the example of selecting a todo in a list of todos:
15
+
16
+ 1. The application creates a local state to store todos. This state contains a `todoSelection` facet.
17
+ 2. When the user clicks on a todo, the todo-list component calls `todoSelection.selectItem(todo.id, shift, ctrl)`.
18
+ 3. The `aspiration` library intercepts the call in order to prepare a so-called `callbackMap`.
19
+ 4. Next, the `todoSelection.selectItem` function runs. It uses the `select` function from the `callbackMap` to do its work.
20
+ 5. The `select` callback performs the selection and a side-effect: it highlights the item as well.
21
+
22
+ ## Benefits
23
+
24
+ There are three ways in which facets help you to write generic code:
25
+
26
+ 1. They can be reused in any container, regardless of what data-type is stored in the container. This means that selection, filtering and drag-and-drop work the same everywhere in the application.
27
+ 2. They allow you to capture the interaction between behaviours in reusable functions.
28
+ 3. They allow you to handle user-interaction in UI components in a uniform way. All UI components that receive a selection facet will use the same interface to make a selection (and in theory the component can remain agnostic of the data-type of the selected items).
6
29
 
7
30
  ## Links
8
31
 
@@ -15,64 +38,97 @@ The goal of SkandhaJS is to provide data containers that have reusable behaviors
15
38
  ## Glossary (conceptual)
16
39
 
17
40
  - callback function: a function that is called by an operation to help implement that operation
18
- - callbacks object: a collection of callback functions that is used by an operation.
19
- - container: a class that contains multiple facets. Typically, these facets are made to work together using callback functions.
41
+ - callbackMap object: a collection of callback functions that is used by an operation.
42
+ - container: an object that contains data and facets. Typically, these facets are made to work together using callback functions.
20
43
  - facet: a class that implements a reusable behaviour, such as selection.
21
44
  - operation: a member function of a facet that changes the data of that facet.
22
45
 
23
46
  ## Glossary (technical)
24
47
 
25
48
  - aspiration: a library that implements a form of Aspect Oriented Programming using callback functions.
26
- - mapDataToProps: a helper function that maps data from one object to another. It's also used to map data between facets.
49
+ - mapDataToProps: a helper function that maps data from one object to another. It's used to map data between facets.
27
50
  - registerCtr: the function that tells SkandhaJS which containers and facets exist.
28
- - setCallbackMap: the function that installs the callbacks objects that are used by a facet.
51
+ - setCallbackMap: the function that installs the callbackMap objects that are used by a facet.
29
52
 
30
- ## Example: a simplified Selection facet
53
+ ## Example: a Selection facet
31
54
 
32
- In Skandha, behaviours (such as selection, or filtering) are implemented in so-called facets that live in containers. For example, a todo container may have facets for selecting, highlighting and filtering todos. Because facets are reusable, they can also be used in other containers. And because facets are abstractions, you can use them to create UI components that handle selection in any container. In this example, we will show a simplified Selection facet class.
55
+ In Skandha, a behaviour such as selection is implemented in a "facet" class. The purpose of the selection facet is to store (and manipulate) the meta-data related to selection. In this example, we will show a simplified Selection facet class.
33
56
 
34
57
  ```
35
58
  // file: Selection.ts
36
59
  import { input, output, operation } from 'skandha';
37
-
38
- export type SelectionParamsT = { itemId?: string; isShift?: boolean; isCtrl?: boolean; };
60
+ import { host, stub } from 'aspiration';
61
+ import { Selection_selectItem, SelectionParamsT } from 'SelectionCbs';
39
62
 
40
63
  export class Selection<ValueT = any> {
41
64
  static className = () => 'Selection';
42
65
 
43
- @input selectableIds: Array<string> = [];
66
+ @input selectableIds: Array<string> = stub();
44
67
  @output ids: Array<string> = [];
45
68
  @output anchorId?: string;
46
- @output items: Array<ValueT> = [];
69
+ @output items: Array<ValueT> = stub();
47
70
 
48
- @operation selectItem(selectionParams: SelectionParamsT) {
49
- // This function calls a callback function to do the actual work.
50
- // Details about how this works are omitted for now.
71
+ @operation @host(['selectionParams']) selectItem(
72
+ selectionParams: SelectionParamsT
73
+ ) {
74
+ const cbs = getCallbacks<Selection_selectItem>(this);
75
+ cbs.select();
51
76
  }
52
77
  }
53
78
  ```
54
79
 
55
- ## Fact: facets have @input, @data and @output members
80
+ ```
81
+ // file: SelectionCbs.ts
82
+ import { stub } from 'aspiration';
56
83
 
57
- In `Selection.ts` we see the Selection facet class. It has a `selectableIds` field that stores the list of ids from which we can select. It is marked with the `@input` decorator because this field stores an input. The `ids`, `anchorId` and `items` fields are marked as `@output` fields. They are used to store the result of calling `selectItem()`. Fields that are decorated with `@data` are used both as output and input.
84
+ export type SelectionParamsT = { itemId?: string; isShift?: boolean; isCtrl?: boolean; };
58
85
 
59
- ## Fact: operations are decorated with `@operation`.
86
+ export class Selection_selectItem extends Cbs {
87
+ selectionParams: SelectionParamsT = stub();
88
+ select() {}
89
+ }
90
+ ```
91
+
92
+ ## Facets have @input, @data and @output members
93
+
94
+ In `Selection.ts` we see the Selection facet class. It has a `selectableIds` field that stores the list of ids from which we can select. The `@input` decorator marks this field as an input. The `ids`, `anchorId` and `items` fields are marked as `@output` fields. They are used to store the result of calling `selectItem()`. Fields that are decorated with `@data` are used both as output and input. These decorators help with logging, and they also make it possible to bind the facets to state-management solutions such as MobX.
95
+
96
+ ## Operations are decorated with `@operation`.
97
+
98
+ The `Selection` facet has a `selectItem()` operation that allows you to select from the selectable ids. It stores its results in the `ids`, `anchorId` and `items` fields. As the comment mentions, `selectItem()` calls a callback function to do the actual work. This design leaves the selection method (e.g. what should happen if shift is pressed?) up to the client, which makes it possible to support different use-cases flexibly.
99
+
100
+ ## Operations are logged
101
+
102
+ As a side effect of calling an operation, the entire container is logged to the console (if logging is enabled); this includes the Selection facet, and any other facets that the container may have (such as filtering, or highlight). The log message contains all @input, @data and @output fields of all facets in the container.
103
+
104
+ ## The `@host` decorator is used to enable callbacks in an operation.
105
+
106
+ The `@host` decorator comes from the `Aspiration` library. When you call a function `f` that is decorated with `@host` then the following happens:
107
+
108
+ - Aspiration looks up the callbackMap object (that was installed with `setCallbackMap()`) for the given operation;
109
+ - it copies the operation arguments to the callbackMap object, so that callback functions can access these arguments;
110
+ - if calls `f(arguments)`;
111
+ - it restores the callbackMap object to its previous state. This ensures that nested calls work correctly.
112
+
113
+ If the original function `f` wants to access the callbackMap object then it uses the `getCallbacks` helper function. Note that the client code calls `f` in the usual way; it remains agnostic of the fact that callbacks are used to help implement `f`.
60
114
 
61
- The `Selection` facet has a `selectItem()` operation that allows you to select from the selectable ids. It stores its results in the `ids`, `anchorId` and `items` fields.
62
- As the comment mentions, `selectItem()` calls a callback function to do the actual work. The reason is that the correct way to make a selection (e.g. what should happen if shift is pressed?) depends on the use-case. Therefore, we want to leave it up to the client to decide this.
115
+ ## Callback functions have access to all operation arguments
63
116
 
64
- ## Fact: operations are logged
117
+ Each callback function of the callbackMap object has access to all arguments of the operation. In our example, the argument of the `selectItem` operation is named `selectionParams`. Therefore, a `selectionParams` field also exists in the `Selection_selectItem` class that stores the callbackMap. We must manually pass the list of argument names to the `@host` decorator, so that SkandhaJS can copy these values (unfortunately, introspection in typescript is not good enough to automate this).
65
118
 
66
- As a side effect of calling an operation, the entire container is logged to the console; this includes the Selection facet, and any other facets that the container may have (such as filtering, or highlight). The log message contains all @input, @data and @output fields of all facets in the container.
119
+ ## Facets have a static `className()` function
120
+
121
+ To allow SkandhaJS to log the container, you need to add the `className()` function to each facet class, so that Skandha knows the name of the facet.
67
122
 
68
123
  ## Example: a container with Selection, Highlight and Filtering
69
124
 
70
125
  Now that we have some idea of what a facet is, we will discuss containers.
71
- In this example we will take a look at a todos container. It uses the `Selection` facet that we saw earlier (and some other facets that we haven't defined yet).
126
+ In this example we will take a look at a todos container. It uses the `Selection` facet that we saw earlier (and some other facets that we haven't defined yet). Note that in this example, we're not yet storing any data in the container (this will come later).
72
127
 
73
128
  ```
74
129
  // file: createContainer.ts
75
130
  import { Selection_selectItem } from 'SelectionCbs';
131
+ import * as R from 'ramda';
76
132
 
77
133
  const createContainer() {
78
134
  const todosCtr = {
@@ -90,6 +146,8 @@ const createContainer() {
90
146
  }
91
147
  });
92
148
 
149
+ setCallbackMap(todosCtr.highlight, {});
150
+
93
151
  setCallbackMap(todosCtr.filtering, {
94
152
  apply: {
95
153
  exit() {
@@ -141,109 +199,56 @@ export function handleSelectItem(
141
199
  }
142
200
  ```
143
201
 
144
- ## Note: the todos container has selection, highlight and filtering
145
-
146
- In `createContainer.ts` we see how `createContainer()` creates a `todosCtr` object that has three facets: selection, highlight and filtering. After creating the container, the `installCallbacks()` function is called to determine how the facet operations are implemented. In this case, we only install the `select()` callback function.
202
+ ## Callbacks are installed with `setCallbackMap()`
147
203
 
148
- ## Fact: callbacks are installed with `setCallbackMap()`
204
+ We call `setCallbackMap()` to install a callbackMap object for each operation of the `Selection` facet. In our case we only have one operation (`selectItem()`) that has only one callback (`select()`). This callback function calls `handleSelectItem()` to take care of doing the selection. This is a typical pattern: you want the call to `setCallbackMap()` to be as short and readable as possible, so that it's easy to understand what happens in each operation of each facet.
149
205
 
150
- We call `setCallbackMap()` to install a callbacks object for each operation of the `Selection` facet. In our case we only have one operation (`selectItem()`) that has only one callback (`select()`). This callback function calls `handleSelectItem()` to take care of doing the selection. This is a typical pattern: you want the call to `setCallbackMap()` to be as short and readable as possible, so that it's easy to understand what happens in each operation of each facet.
206
+ ## Callbacks can take care of side effects
151
207
 
152
- ## Fact: callbacks can take care of side effects
208
+ An important advantage of using callbacks is that they can also take care of side effects. In this case, it calls `highlightFollowsSelection()` to ensure that selected items are also highlighted. Note that the callback function is able to connect selection and highlight because it has access to the entire container. Keeping the code of `setCallbackMap()` short also helps the reader to understand which interactions take place. This is vital, because we are purposely mixing concerns in this part of the code, which means that there is a higher risk of confusing the reader.
153
209
 
154
- An important advantage of using callbacks is that they can also take care of side effects. In this case, it calls `highlightFollowsSelection()` to ensure that selected items are also highlighted. Note that the callback function is able to connect selection and highlight because it has access to the entire container.
155
-
156
- ## Fact: the callback function can access the callbacks object through `this`.
210
+ ## The callback function can access the callbackMap object through `this`.
157
211
 
158
212
  When the clients calls `todosCtr.selection.selectItem()` and `select()` is called back, then all arguments of the operation are available through `this`. In our case, we see that the `select()` callback function is accessing `this.selectionParams`.
159
213
 
160
- ## Fact: the `exit()` callback function is called at the end of an operation
214
+ ## The `exit()` callback function is called at the end of an operation
161
215
 
162
- In `createContainer.ts` we also have a `Filtering` facet that has an `apply(f)` operation (where `f` is the filter function). In this operation, we install the `exit()` callback that corrects the highlight when the filter function changes (because the new filter may hide the highlighted item). The `exit()` callback is called automatically at the end of each operation. Similarly, the `enter()` callback is called at the beginning.
216
+ In `createContainer.ts` we also have a `Filtering` facet that has an `apply(f)` operation (where `f` is the filter function). In this operation, we install the `exit()` callback that corrects the highlight when the filter function changes (because the new filter may hide the highlighted item). The `exit()` callback is called automatically at the end of each operation. Similarly, the `enter()` callback is called automatically at the beginning.
163
217
 
164
- ## Fact: the `registerCtr()` allows SkandhaJS to introspect the container
218
+ ## The `registerCtr()` allows SkandhaJS to introspect the container
165
219
 
166
- At the end of `createContainer.ts` we call `registerCtr()` so that SkandhaJS can introspect the container. This is necessary for two reasons. First, it makes it possible to look up a facet by its name or class, e.g. `getf(todosCtr, Selection)` returns `todosCtr.selection`. Second, it informs SkandhaJS how to log all facets of the container
220
+ At the end of `createContainer.ts` we call `registerCtr()` so that SkandhaJS can introspect the container. This is necessary for two reasons. First, it makes it possible to look up a facet by its name or class, e.g. `getf(todosCtr, Selection)` returns `todosCtr.selection`. Second, it informs SkandhaJS how to log all facets of the container.
167
221
 
168
- ## Example: a complete Selection facet
222
+ ## Example: `mapDataToProps()` maps data onto each facet
169
223
 
170
- It's time now to return to the Selection facet and show how callbacks really work.
224
+ We've seen how facets are implemented, and how they can be added to a container in a way that allows us to create interactions between them. The next step is to map data between facets. Such mappings are necessary when the input data for one facet is based on the output data of another facet. For example, we should only allow selection of todos that have not been filtered out. In this example, we will see how we can create such a mapping. Moreover, we will add code to load the todos and set them as the inputs of the filtering facet.
171
225
 
172
226
  ```
173
- // file: Selection.ts
174
- import { input, output, operation } from 'skandha';
175
- import { host, stub } from 'aspiration';
176
- import { Selection_selectItem, SelectionParamsT } from 'SelectionCbs';
227
+ // file: createContainer.ts
228
+ import * from 'ramda' as R;
229
+ import { mapDataToProps, pmap } from 'skandha';
177
230
 
178
- export class Selection<ValueT = any> {
179
- static className = () => 'Selection';
231
+ class TodosData {
232
+ static className = () => 'Inputs';
180
233
 
181
- @input selectableIds: Array<string> = stub();
182
- @output ids: Array<string> = [];
183
- @output anchorId?: string;
184
- @output items: Array<ValueT> = stub();
234
+ @data todos: TodoT[] = [];
235
+ @data filteredTodos: TodoT[] = [];
185
236
 
186
- @operation @host(['selectionParams']) selectItem(
187
- selectionParams: SelectionParamsT
188
- ) {
189
- return (cbs: Selection_selectItem) => {
190
- cbs.select();
191
- };
237
+ @data get todoById() {
238
+ return R.indexBy(R.prop('id'), todosCtr);
192
239
  }
193
240
  }
194
- ```
195
-
196
- ```
197
- // file: SelectionCbs.ts
198
- import { stub } from 'aspiration';
199
-
200
- export type SelectionParamsT = { itemId?: string; isShift?: boolean; isCtrl?: boolean; };
201
-
202
- export class Selection_selectItem extends Cbs {
203
- selectionParams: SelectionParamsT = stub();
204
- select() {}
205
- }
206
- ```
207
-
208
- ## Fact: the `@host` decorator is used to enable callbacks in an operation.
209
-
210
- The `@host` decorator comes from the `Aspiration` library. When you call a function `f` that is decorated with `@host` then the following happens:
211
-
212
- - Aspiration looks up the callbacks object for the operation (that was installed with `setCallbackMap()`)
213
- - it copies the operation arguments to the callbacks object (so that callback functions can access these arguments)
214
- - if calls `f(arguments)(callbacksObject)`.
215
-
216
- Remember that `f` is the original function. We see from the example that `f` returns a closure. This closure receives the callbacks object, but (because it's a closure) it also has access to the arguments of f. This approach allows the client code to call `f` in the usual way; it can be agnostic of the fact that callbacks are used to help implement `f`.
217
-
218
- ## Fact: callback functions have access to all operation arguments
219
-
220
- As we mentioned earlier, each callback function of the callbacks object has access to all arguments of the operation. For this to work, it's required that you pass the list of argument names to the `@host` decorator (unfortunately, typescript does not have introspection capabilities that allow to automate this). These names need to match the corresponding fields of the callbacks object class (`Selection_selectItem`).
221
-
222
- ## Fact: facets have a static `className()` function
223
-
224
- To allow SkandhaJS to introspect the container, you need to add the `className()` function to each facet class, so that Skandha knows the name of the facet.
225
-
226
- ## Example: `mapDataToProps()` maps data onto each facet
227
-
228
- We've seen how facets are implemented, and how they can be added to a container in a way that allows us to create interactions between them. Since our container contains selection and filtering, we should only allow selection of todos that have not been filtered out. In other words, the list of selectable ids should be derived from the list of filtered todos. In this example, we will see how we can create such a mapping from the filtering facet to the selection facet. Moreover, we will add code to load the todos and set them as the inputs of the filtering facet.
229
-
230
- ```
231
- // file: createContainer.ts
232
- import * from 'ramda' as R;
233
- import { mapDataToProps, pmap } from 'skandha';
234
241
 
235
242
  const createContainer = () => {
236
243
  const todosCtr = {
237
- data: {
238
- todos: loadTodos(),
239
- filteredTodoById: {},
240
- },
244
+ data: new TodosData(),
241
245
  selection: new Selection(),
242
246
  highlight: new Highlight(),
243
247
  filtering: new Filtering(),
244
248
  }
249
+ todosCtr.data.todos = loadTodos();
245
250
 
246
- const lookUpTodo = (id?: string) => id ? todosCtr.data.filteredTodoById[id] : undefined;
251
+ const getTodoById = (id?: string) => id ? todosCtr.data.todoById[id] : undefined;
247
252
 
248
253
  mapDataToProps(
249
254
  pmap(
@@ -251,20 +256,20 @@ const createContainer = () => {
251
256
  () => todosCtr.data.todos
252
257
  ),
253
258
  pmap(
254
- [todosCtr.data, 'filteredTodoById'],
255
- () => R.indexBy('id')(todosCtr.filtering.filteredItems)
259
+ [todosCtr.data, 'filteredTodos'],
260
+ () => todosCtr.filtering.filteredItems
256
261
  ),
257
262
  pmap(
258
263
  [todosCtr.selection, 'selectableIds'],
259
- () => R.keys(todosCtr.data.filteredTodoById)
264
+ () => R.map(R.prop('id'), todosCtr.data.filteredTodos)
260
265
  ),
261
266
  pmap(
262
- [todosCtr.selection, 'item'],
263
- () => R.map(lookUpTodo, todosCtr.selection.ids)
267
+ [todosCtr.selection, 'items'],
268
+ () => R.map(getTodoById, todosCtr.selection.ids)
264
269
  ),
265
270
  pmap(
266
271
  [todosCtr.highlight, 'item'],
267
- () => lookUpTodo(todosCtr.highlight.id)
272
+ () => getTodoById(todosCtr.highlight.id)
268
273
  ),
269
274
  )
270
275
  }
@@ -272,25 +277,25 @@ const createContainer = () => {
272
277
  setOptions({logging: true});
273
278
  ```
274
279
 
275
- ## Fact: the `mapDataToProps()` function maps data between objects
280
+ ## The `mapDataToProps()` function maps data between objects
276
281
 
277
- The `mapDataToProp()` function takes a container, field name and function then it turns that field into a `get` property that executes the given function. The `mapDataToProps()` is a small convenience function that calls `mapDataToProp()` on each of its arguments. In our example, we see that the `todosCtr.data.todos` field is mapped onto the `todosCtr.filtering.inputItems` field.
282
+ The `mapDataToProp()` function takes a container, field name and function and installs a `get` property (on the given container, using the given field name) that executes the given function. The `mapDataToProps()` is a small convenience function that calls `mapDataToProp()` on each of its arguments. In our example, we see that the `todosCtr.data.todos` field is mapped onto the `todosCtr.filtering.inputItems` field.
278
283
 
279
- ## Fact: the `pmap()` function adds type-checking
284
+ ## The `pmap()` function adds type-checking
280
285
 
281
- The `pmap()` function takes two arguments. The first argument is an array that has a container and a container-member. The second argument is a function. The `pmap` function checks that the output of this function can be stored in the container-member (if not, then a compile-time error results). It returns an array that contains its two arguments (because that is the format that `mapDataToProps` expects). As you can see, `pmap` does not do any useful work at run-time, but it adds type-checking at compile-time.
286
+ The `pmap` function does not really do anything at run-time, but it adds type-checking at compile-time. It takes two arguments. The first argument is an array that has a container and a container-member. The second argument is a function. The `pmap` function checks that the output of this function can be stored in the container-member (if not, then a compile-time error results). It returns an array that contains its two arguments (because that is the format that `mapDataToProps` expects).
282
287
 
283
- ## Fact: logging can be enabled using `setOptions()`
288
+ ## Logging can be enabled using `setOptions()`
284
289
 
285
- By calling `setOptions({logging: true})`, the SkandhaJS library allows you to inspect each facet before and after calling an operation. All facet members that are decorated with `@data` (or `@input`, or `@output`) are logged in a way that looks similar to what you are used to from Redux:
290
+ If you call `setOptions({logging: true})` then the SkandhaJS library logs each facet before and after each operation. All facet members that are decorated with `@data` (or `@input`, or `@output`) are logged in a way that looks similar to what you are used to from Redux:
286
291
 
287
292
  - before and after each operation, the entire container that holds the facet is logged
288
293
  - all data members of each facet in the container are included in the log
289
294
  - log entries are nested so that you can see how operation calls are nested
290
295
 
291
- ## Fact: the `registerCtr()` function from facets-mobx makes facets observable
296
+ ## The `registerCtr()` function from facets-mobx makes facets observable
292
297
 
293
- If you want to render the facets with React then we need to let React know when data changes. The [skandha-mobx](http://github.com/mnieber/skandha-mobx) library was created for this purpose. It has a `registerCtr()` function that can be used instead of the default one from `skandha`. This replacement version of `registerCtr()` function turns each `@data` member into a Mobx property that is either observable or computed.
298
+ If you want to render the facets with React then we need to let React know when data changes. The [skandha-mobx](http://github.com/mnieber/skandha-mobx) library was created for this purpose. It has a `registerCtr()` function that can be used instead of the default one from `skandha`. This drop-in replacement version of the normal `registerCtr()` function turns each `@data` member into a Mobx property that is either observable or computed.
294
299
 
295
300
  ## Conclusion
296
301
 
@@ -301,5 +306,4 @@ separating concerns in a clear and understandable way. We could add a `Editing`
301
306
  a policy that says that changing the highlight disables editing. By using facets, we will not be tempted to put
302
307
  editing-specific code directly in the highlight function (that would obviously be mixing concerns).
303
308
 
304
- In my experience, using SkandhaJS leads to code reuse and improved structure. On top of that, it offers a good
305
- debugging experience by logging all changes in the container. Finally, it works nicely with MobX to render the container contents.
309
+ In my experience, using SkandhaJS leads to code reuse and improved structure. On top of that, it offers a good debugging experience by logging all changes in the container. Finally, it works nicely with MobX to render the container contents.
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { getCtrState } from './internal/logging';
2
- export { getOptions, setOptions } from './internal/options';
2
+ export { decorateCb, getOptions, setOptions } from './internal/options';
3
3
  export { getc, getFacetMemberNames } from './lib/ctr';
4
4
  export { data, getDataMemberNames, getLoggedMemberNames, input, log, output, } from './lib/data';
5
5
  export { getf } from './lib/facet';
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { getCtrState } from './internal/logging';
2
- export { getOptions, setOptions } from './internal/options';
2
+ export { decorateCb, getOptions, setOptions } from './internal/options';
3
3
  export { getc, getFacetMemberNames } from './lib/ctr';
4
4
  export { data, getDataMemberNames, getLoggedMemberNames, input, log, output, } from './lib/data';
5
5
  export { getf } from './lib/facet';
@@ -1,9 +1,12 @@
1
1
  export declare const options: {
2
2
  logging: boolean;
3
3
  formatObject: (x: any) => any;
4
+ decorateCb: (x: any) => any;
4
5
  };
5
6
  export declare const getOptions: () => {
6
7
  logging: boolean;
7
8
  formatObject: (x: any) => any;
9
+ decorateCb: (x: any) => any;
8
10
  };
9
11
  export declare const setOptions: (moreOptions: any) => void;
12
+ export declare const decorateCb: (x: any) => any;
@@ -1,8 +1,10 @@
1
1
  export var options = {
2
2
  logging: false,
3
3
  formatObject: function (x) { return x; },
4
+ decorateCb: function (x) { return x; },
4
5
  };
5
6
  export var getOptions = function () { return options; };
6
7
  export var setOptions = function (moreOptions) {
7
8
  Object.assign(options, moreOptions);
8
9
  };
10
+ export var decorateCb = function (x) { return options.decorateCb(x); };
package/internal/utils.js CHANGED
@@ -1,7 +1,11 @@
1
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
2
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
3
- to[j] = from[i];
4
- return to;
1
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
+ if (ar || !(i in from)) {
4
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
+ ar[i] = from[i];
6
+ }
7
+ }
8
+ return to.concat(ar || Array.prototype.slice.call(from));
5
9
  };
6
10
  import { symbols } from './symbols';
7
11
  export function getOrCreate(obj, key, fn) {
@@ -16,7 +20,7 @@ export var zip = function (arr) {
16
20
  arrs[_i - 1] = arguments[_i];
17
21
  }
18
22
  return arr.map(function (val, i) {
19
- return arrs.reduce(function (a, arr) { return __spreadArray(__spreadArray([], a), [arr[i]]); }, [val]);
23
+ return arrs.reduce(function (a, arr) { return __spreadArray(__spreadArray([], a, true), [arr[i]], false); }, [val]);
20
24
  });
21
25
  };
22
26
  export function getCtrAdmin(ctr) {
package/lib/facet.js CHANGED
@@ -11,7 +11,7 @@ export function getf(facetClass, ctr) {
11
11
  : (_a = getCtrAdmin(ctr).facetByFacetClassName) === null || _a === void 0 ? void 0 : _a[facetClassName(facetClass)];
12
12
  if (!facet) {
13
13
  var facetName = facetClass === 'string' ? facetClass : facetClassName(facetClass);
14
- console.error("No facet " + facetName + " in container " + getCtrAdmin(ctr).logName);
14
+ console.error("No facet ".concat(facetName, " in container ").concat(getCtrAdmin(ctr).logName));
15
15
  }
16
16
  return facet;
17
17
  }
@@ -15,13 +15,13 @@ export function registerCtr(ctr, options) {
15
15
  setCtr(facet, ctr);
16
16
  ctrAdmin.facetMembers.push(facetName);
17
17
  if (!facet.constructor.className) {
18
- console.error("Facet " + facetName + " of container " + ctrAdmin.logName + " " +
18
+ console.error("Facet ".concat(facetName, " of container ").concat(ctrAdmin.logName, " ") +
19
19
  "does not have a static className function");
20
20
  }
21
21
  var className = facetClassName(facet.constructor);
22
- getFacetAdmin(facet).logName = ctrAdmin.logName + "/" + className;
22
+ getFacetAdmin(facet).logName = "".concat(ctrAdmin.logName, "/").concat(className);
23
23
  if (ctrAdmin.facetByFacetClassName[className] !== undefined) {
24
- console.error("Two facets of same type " + className + " in container " + ctrAdmin.logName);
24
+ console.error("Two facets of same type ".concat(className, " in container ").concat(ctrAdmin.logName));
25
25
  }
26
26
  ctrAdmin.facetByFacetClassName[className] = facet;
27
27
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skandha",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "description": "Create data containers with modular behaviours",
5
5
  "main": "index.js",
6
6
  "repository": "https://github.com/mnieber/skandha.git",