Skip to content

Commit aade265

Browse files
committed
feat!: change Lazy Data arguments signature with (resolve, reject)
1 parent ed31688 commit aade265

26 files changed

+408
-266
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Changes and new options:
110110
- `onClose(reason)` callback that will be executed when the dropdown closes (see [demo](https://ghiscoding.github.io/multiple-select-vanilla/#/events))
111111
- `preFilter` provide a Filter predicate to pre-filter data (see [demo](https://ghiscoding.github.io/multiple-select-vanilla/#/options40))
112112
- `preSort` provide a Sort Comparer to pre-sort data (see [demo](https://ghiscoding.github.io/multiple-select-vanilla/#/options41))
113-
- `lazyData` provide a function callback that will return a Promise with data collection (see [demo](https://ghiscoding.github.io/multiple-select-vanilla/#/options42))
113+
- `lazyData` provide a function with callback arguments to load data asynchronously (see [demo](https://ghiscoding.github.io/multiple-select-vanilla/#/options42))
114114
115115
## CSP Compliance
116116
The library is now CSP (Content Security Policy) compliant, there are however some exceptions to be aware of. When using any HTML strings as template (when using `textTemplate`, `labelTemplate`, `renderOptionLabelAsHtml` or `useSelectOptionLabelToHtml`), you will not be fully compliant unless you return [`TrustedHTML`](https://developer.mozilla.org/en-US/docs/Web/API/TrustedHTML). You can achieve this by using the `sanitizer` method in combo with an external library like [DOMPurify](https://github.com/cure53/DOMPurify) (recommended) to return `TrustedHTML` as shown below and with that in place you will be CSP compliant.
@@ -149,9 +149,12 @@ with this code in place, we can now use the following CSP meta tag (which is wha
149149
### version 4.0
150150
- build ESM-Only and drop CJS (CommonJS) build (aka `require()`)
151151
152+
152153
### version 5.0
153154
154-
Locale management has been refactored to remove usage of the global `window` object. Locales are now provided via a modular registry and injected through options. This change affects how you load, switch, and reference locales. Also, the `multiple-select-` prefix has been removed from all locale import paths (single and merged) and no longer exists on the `window` object
155+
- **Locale management** has been refactored to remove usage of the global `window` object. Locales are now provided via a modular registry and injected through options. The `multiple-select-` prefix has been removed from all locale import paths (single and merged) and no longer exists on the `window` object.
156+
157+
- **Lazy loading API change:** The `lazyData` option now uses a callback signature: `lazyData(resolve, reject)` instead of returning a Promise. This allows for more flexible async data loading and error handling. See the demo and documentation for updated usage examples.
155158
156159
**Migration Example:**
157160
@@ -172,6 +175,10 @@ Locale management has been refactored to remove usage of the global `window` obj
172175
+ import { locales } from 'multiple-select-vanilla/dist/locales/all-locales.js';
173176
+ // OR default import
174177
+ import locales from 'multiple-select-vanilla/dist/locales/all-locales.js';
178+
179+
// 3. lazyData option (old vs new)
180+
- lazyData: () => Promise<CollectionData>
181+
+ lazyData: (resolve, reject) => void
175182
```
176183
177184
See the [Example09](https://ghiscoding.github.io/multiple-select-vanilla/#/example09) for details on dynamic locale loading.

packages/demo/src/options/options42.html

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ <h2 class="bd-title">
1616
</span>
1717
</h2>
1818
<div class="demo-subtitle">
19-
Use <code>&#123; lazyData: () => Promise &#125;</code>to lazy load data only after clicking and opening the select dropdown. Note that
20-
once the data is loaded, it no longer needs to be lazy loaded again and so re-opening the select dropdown will show instantly
21-
afterward. You can refresh the page, or click the button to retest the lazy loading. Also note that any pre-selected options will only
22-
show up after the data is fully loaded.
19+
Use <code>&#123; lazyData: (resolve, reject) &#125;</code>to lazy load data, the 2 arguments are callback functions to call when the
20+
data is ready. Lazy data will only be loaded once and reopening the dropdown will show instantly. If a failure happened and the
21+
<code>reject</code> callback is called, it will be retried after you close and reopen the dropdown. For testing purposes, you can
22+
refresh the page or click the button to retest the lazy loading. <br>
23+
<strong>Note:</strong> any pre-selected options will only show up after the data is fully loaded (e.g. 4th select with "Filter &amp;
24+
OK button").
2325
</div>
2426
</div>
2527
</div>
@@ -65,4 +67,12 @@ <h2 class="bd-title">
6567
<select id="group" class="full-width" multiple data-test="select4"></select>
6668
</div>
6769
</div>
70+
71+
<div class="mb-3 row">
72+
<label class="col-sm-2">Lazy Data Failure</label>
73+
74+
<div class="col-sm-10">
75+
<select id="group" class="full-width" multiple data-test="select5"></select>
76+
</div>
77+
</div>
6878
</div>

0 commit comments

Comments
 (0)