Skip to content

Commit

Permalink
rewrite in typescript with LitElement
Browse files Browse the repository at this point in the history
  • Loading branch information
bennypowers committed Jun 11, 2020
1 parent 3e38a25 commit 0881ba2
Show file tree
Hide file tree
Showing 52 changed files with 17,053 additions and 4,136 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/bower_components
**/*~
/node_modules
*.js
*.js.map
*.d.ts
!karma.conf.js
17 changes: 0 additions & 17 deletions .project

This file was deleted.

6 changes: 0 additions & 6 deletions .settings/.jsdtscope

This file was deleted.

1 change: 0 additions & 1 deletion .settings/org.eclipse.wst.jsdt.ui.superType.container

This file was deleted.

1 change: 0 additions & 1 deletion .settings/org.eclipse.wst.jsdt.ui.superType.name

This file was deleted.

7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"files.exclude": {
"**/*.js": {"when": "$(basename).ts"},
"**/*.d.ts": {"when": "$(basename).ts"},
"**/*.js.map": true
},
}
34 changes: 34 additions & 0 deletions base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { PropertyValues } from 'lit-element';
import { FireMixin } from '@pwrs/mixins/fire';
import { LitElement, property } from 'lit-element';
import { bound } from './bound-decorator';

type LeafletFeature =
| null
| L.Circle
| L.GeoJSON
| L.Marker
| L.LayerGroup
| L.Polyline
| L.Polygon
| L.Popup
| L.Point;

export class LeafletBase extends FireMixin(LitElement) {
@property({ attribute: false }) container: L.Map | L.LayerGroup;

_mutationObserver?: MutationObserver;

feature: LeafletFeature;

containerChanged?(): void;

updated(changed: PropertyValues) {
super.updated?.(changed);
if (changed.has('container')) this.containerChanged?.();
}

@bound onLeafletEvent(e: L.LeafletEvent) {
this.fire(e.type, e);
}
}
5 changes: 5 additions & 0 deletions boilerplate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```html
<script src="https://unpkg.com/@webcomponentsjs/webcomponentsjs/webcomponents-loader.js"></script>
<script type="module" src="https://unpkg.com/leaflet-element?module"></script>
<leaflet-map></leaflet-map>
```
27 changes: 27 additions & 0 deletions bound-decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export function bound<T extends Function>(
target: object,
propertyKey: string,
descriptor: TypedPropertyDescriptor<T>
): TypedPropertyDescriptor<T> | void {
if (!descriptor || typeof descriptor.value !== 'function') {
throw new TypeError(
`Only methods can be decorated with @bound. <${propertyKey}> is not a method!`
);
}

return {
configurable: true,
get(this: T): T {
const f: T = descriptor.value!.bind(this);
// Credits to https://github.com/andreypopp/autobind-decorator for memoizing the result of bind against a symbol on the instance.
Object.defineProperty(this, propertyKey, {
value: f,
configurable: true,
writable: true,
});
return f;
},
};
}

export default bound;
31 changes: 0 additions & 31 deletions bower.json

This file was deleted.

Loading

0 comments on commit 0881ba2

Please sign in to comment.