Skip to content

Commit 0881ba2

Browse files
committed
rewrite in typescript with LitElement
1 parent 3e38a25 commit 0881ba2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+17053
-4136
lines changed

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
/bower_components
2-
**/*~
1+
/node_modules
2+
*.js
3+
*.js.map
4+
*.d.ts
5+
!karma.conf.js

.project

Lines changed: 0 additions & 17 deletions
This file was deleted.

.settings/.jsdtscope

Lines changed: 0 additions & 6 deletions
This file was deleted.

.settings/org.eclipse.wst.jsdt.ui.superType.container

Lines changed: 0 additions & 1 deletion
This file was deleted.

.settings/org.eclipse.wst.jsdt.ui.superType.name

Lines changed: 0 additions & 1 deletion
This file was deleted.

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"files.exclude": {
3+
"**/*.js": {"when": "$(basename).ts"},
4+
"**/*.d.ts": {"when": "$(basename).ts"},
5+
"**/*.js.map": true
6+
},
7+
}

base.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { PropertyValues } from 'lit-element';
2+
import { FireMixin } from '@pwrs/mixins/fire';
3+
import { LitElement, property } from 'lit-element';
4+
import { bound } from './bound-decorator';
5+
6+
type LeafletFeature =
7+
| null
8+
| L.Circle
9+
| L.GeoJSON
10+
| L.Marker
11+
| L.LayerGroup
12+
| L.Polyline
13+
| L.Polygon
14+
| L.Popup
15+
| L.Point;
16+
17+
export class LeafletBase extends FireMixin(LitElement) {
18+
@property({ attribute: false }) container: L.Map | L.LayerGroup;
19+
20+
_mutationObserver?: MutationObserver;
21+
22+
feature: LeafletFeature;
23+
24+
containerChanged?(): void;
25+
26+
updated(changed: PropertyValues) {
27+
super.updated?.(changed);
28+
if (changed.has('container')) this.containerChanged?.();
29+
}
30+
31+
@bound onLeafletEvent(e: L.LeafletEvent) {
32+
this.fire(e.type, e);
33+
}
34+
}

boilerplate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
```html
2+
<script src="https://unpkg.com/@webcomponentsjs/webcomponentsjs/webcomponents-loader.js"></script>
3+
<script type="module" src="https://unpkg.com/leaflet-element?module"></script>
4+
<leaflet-map></leaflet-map>
5+
```

bound-decorator.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export function bound<T extends Function>(
2+
target: object,
3+
propertyKey: string,
4+
descriptor: TypedPropertyDescriptor<T>
5+
): TypedPropertyDescriptor<T> | void {
6+
if (!descriptor || typeof descriptor.value !== 'function') {
7+
throw new TypeError(
8+
`Only methods can be decorated with @bound. <${propertyKey}> is not a method!`
9+
);
10+
}
11+
12+
return {
13+
configurable: true,
14+
get(this: T): T {
15+
const f: T = descriptor.value!.bind(this);
16+
// Credits to https://github.com/andreypopp/autobind-decorator for memoizing the result of bind against a symbol on the instance.
17+
Object.defineProperty(this, propertyKey, {
18+
value: f,
19+
configurable: true,
20+
writable: true,
21+
});
22+
return f;
23+
},
24+
};
25+
}
26+
27+
export default bound;

bower.json

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)