@aarongustafson/pull-to-refresh 0.0.5 → 1.0.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.
- package/README.md +18 -8
- package/define.js +16 -1
- package/index.js +0 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,21 +29,31 @@ npm install @aarongustafson/pull-to-refresh
|
|
|
29
29
|
|
|
30
30
|
### Usage
|
|
31
31
|
|
|
32
|
-
**Option 1:
|
|
32
|
+
**Option 1: Manual registration**
|
|
33
33
|
```javascript
|
|
34
|
-
import '@aarongustafson/pull-to-refresh';
|
|
34
|
+
import { PullToRefreshElement } from '@aarongustafson/pull-to-refresh';
|
|
35
|
+
|
|
36
|
+
customElements.define('pull-to-refresh', PullToRefreshElement);
|
|
35
37
|
```
|
|
36
38
|
|
|
37
|
-
**Option 2:
|
|
39
|
+
**Option 2: Auto-define (browser environments only)**
|
|
38
40
|
```javascript
|
|
39
|
-
import
|
|
40
|
-
|
|
41
|
+
import '@aarongustafson/pull-to-refresh/define.js';
|
|
42
|
+
// Registers <pull-to-refresh> when customElements is available
|
|
41
43
|
```
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
Prefer to control when registration happens? Call the helper directly:
|
|
46
|
+
|
|
44
47
|
```javascript
|
|
45
|
-
import {
|
|
46
|
-
|
|
48
|
+
import { definePullToRefresh } from '@aarongustafson/pull-to-refresh/define.js';
|
|
49
|
+
|
|
50
|
+
definePullToRefresh();
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
You can also include the guarded script from HTML:
|
|
54
|
+
|
|
55
|
+
```html
|
|
56
|
+
<script src="./node_modules/@aarongustafson/pull-to-refresh/define.js" type="module"></script>
|
|
47
57
|
```
|
|
48
58
|
|
|
49
59
|
### Basic Example
|
package/define.js
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
1
|
import { PullToRefreshElement } from './pull-to-refresh.js';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export function definePullToRefresh(tagName = 'pull-to-refresh') {
|
|
4
|
+
const hasWindow = typeof window !== 'undefined';
|
|
5
|
+
const registry = hasWindow ? window.customElements : undefined;
|
|
6
|
+
|
|
7
|
+
if (!registry || typeof registry.define !== 'function') {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (!registry.get(tagName)) {
|
|
12
|
+
registry.define(tagName, PullToRefreshElement);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
definePullToRefresh();
|
package/index.js
CHANGED