Skip to content

Commit 65ad0d1

Browse files
committed
docs: document constructorOptionDefaults
1 parent fc93376 commit 65ad0d1

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

CONTRIBUTING.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
- [Your First Contribution](#your-first-contribution)
99
- [Submitting code](#submitting-code)
1010
- [Code review process](#code-review-process)
11-
- [Financial contributions](#financial-contributions)
1211
- [Questions](#questions)
1312
- [Credits](#credits)
1413
- [Contributors](#contributors)
15-
- [Backers](#backers)
1614
- [Sponsors](#sponsors)
1715

1816
<!-- END doctoc generated TOC please keep comment here to allow auto update -->

README.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ There are also reasons not to choose this package. Because of all it does, this
3131
- [Validate a MongoDB Modifier](#validate-a-mongodb-modifier)
3232
- [Enable Meteor Tracker Reactivity](#enable-meteor-tracker-reactivity)
3333
- [Automatically Clean the Object Before Validating It](#automatically-clean-the-object-before-validating-it)
34-
- [Set Default Cleaning Options](#set-default-cleaning-options)
34+
- [Set Default Options for One Schema](#set-default-options-for-one-schema)
35+
- [Set Default Options for All Schemas](#set-default-options-for-all-schemas)
3536
- [Explicitly Clean an Object](#explicitly-clean-an-object)
3637
- [Defining a Schema](#defining-a-schema)
3738
- [Shorthand Definitions](#shorthand-definitions)
@@ -90,7 +91,6 @@ There are also reasons not to choose this package. Because of all it does, this
9091
- [Extending the Schema Options](#extending-the-schema-options)
9192
- [Add On Packages](#add-on-packages)
9293
- [Contributors](#contributors)
93-
- [Backers](#backers)
9494
- [Sponsors](#sponsors)
9595
- [License](#license)
9696
- [Contributing](#contributing)
@@ -249,7 +249,7 @@ Passing in `Tracker` causes the following functions to become reactive:
249249

250250
TO DO
251251

252-
### Set Default Cleaning Options
252+
### Set Default Options for One Schema
253253

254254
```js
255255
import SimpleSchema from 'simpl-schema';
@@ -258,16 +258,44 @@ const mySchema = new SimpleSchema({
258258
name: String,
259259
}, {
260260
clean: {
261-
filter: true,
262261
autoConvert: true,
262+
extendAutoValueContext: {},
263+
filter: false,
264+
getAutoValues: true,
263265
removeEmptyStrings: true,
266+
removeNullsFromArrays: false,
264267
trimStrings: true,
265-
getAutoValues: true,
266-
removeNullsFromArrays: true,
267268
},
269+
humanizeAutoLabels: false,
270+
requiredByDefault: true,
271+
});
272+
```
273+
274+
These options will be used every time you clean or validate with this particular SimpleSchema instance.
275+
276+
### Set Default Options for All Schemas
277+
278+
```js
279+
import SimpleSchema from 'simpl-schema';
280+
281+
SimpleSchema.constructorOptionDefaults({
282+
clean: {
283+
filter: false,
284+
},
285+
humanizeAutoLabels: false,
268286
});
287+
288+
// If you don't pass in any options, it will return the current defaults.
289+
console.log(SimpleSchema.constructorOptionDefaults());
269290
```
270291

292+
These options will be used every time you clean or validate with any SimpleSchema instance, but can be overridden by options passed in to the constructor for a single instance.
293+
294+
Important notes:
295+
296+
- You must call `SimpleSchema.constructorOptionDefaults` before any of your schemas are created, so put it in an entry-point file and/or at the top of your code file.
297+
- In a large, complex project where SimpleSchema instances might be created by various JavaScript packages, there may be multiple `SimpleSchema` objects. In other words, the `import SimpleSchema` line in one package might be pulling in the `SimpleSchema` object from one package while that line in another package pulls in a completely different `SimpleSchema` object. It will be difficult to know that this is happening unless you notice that your defaults are not being used by some of your schemas. To solve this, you can call `SimpleSchema.constructorOptionDefaults` multiple times or adjust your package dependencies to ensure that only one version of `simpl-schema` is pulled into your project.
298+
271299
### Explicitly Clean an Object
272300

273301
```js

0 commit comments

Comments
 (0)