forked from Choices-js/Choices
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MAJOR] expose
defaults
and original Template rendering functions (C…
…hoices-js#708) * expose original Template rendering functions * add to types * add moduleResolution * use `defaults`
- Loading branch information
1 parent
1c75147
commit 9504cfc
Showing
4 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,11 +39,28 @@ import { | |
diff, | ||
} from './lib/utils'; | ||
|
||
const USER_DEFAULTS = /** @type {Partial<import('../../types/index').Choices.Options>} */ ({}); | ||
|
||
/** | ||
* Choices | ||
* @author Josh Johnson<[email protected]> | ||
*/ | ||
class Choices { | ||
/* ======================================== | ||
= Static properties = | ||
======================================== */ | ||
|
||
static get defaults() { | ||
return Object.preventExtensions({ | ||
get options() { | ||
return USER_DEFAULTS; | ||
}, | ||
get templates() { | ||
return TEMPLATES; | ||
}, | ||
}); | ||
} | ||
|
||
constructor(element = '[data-choice]', userConfig = {}) { | ||
if (isType('String', element)) { | ||
const elements = Array.from(document.querySelectorAll(element)); | ||
|
@@ -56,7 +73,7 @@ class Choices { | |
} | ||
|
||
this.config = merge.all( | ||
[DEFAULT_CONFIG, Choices.userDefaults, userConfig], | ||
[DEFAULT_CONFIG, Choices.defaults.options, userConfig], | ||
// When merging array configs, replace with a copy of the userConfig array, | ||
// instead of concatenating with the default array | ||
{ arrayMerge: (destinationArray, sourceArray) => [...sourceArray] }, | ||
|
@@ -2108,6 +2125,4 @@ class Choices { | |
/* ===== End of Private functions ====== */ | ||
} | ||
|
||
Choices.userDefaults = {}; | ||
|
||
export default Choices; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters