Skip to content

Commit fc7f7b5

Browse files
committed
Convert to Typescript
1 parent b418959 commit fc7f7b5

31 files changed

+778
-605
lines changed

.babelrc

-3
This file was deleted.

.eslintrc

-22
This file was deleted.

.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
build
1+
.rpt2_cache
22
bower_components
3-
node_modules
3+
build
44
components
5+
node_modules

.jscsrc

-31
This file was deleted.

.jshintrc

-33
This file was deleted.

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"tabWidth": 4,
4+
"trailingComma": "all",
5+
}

examples/observing-keys.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
}
9393
console.info('Tests: OK');
9494
return true;
95-
}
95+
}
9696
});
9797
</script>
9898

lib/LocalForageObservableWrapper.js

-31
This file was deleted.

lib/LocalForageObservableWrapper.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { ObservableLibraryMethods } from './ObservableLibraryMethods';
2+
3+
export class LocalForageObservableWrapper {
4+
constructor(
5+
public options: LocalForageObservableOptions,
6+
private subscriptionObserver: Observer<LocalForageObservableChange>,
7+
) {}
8+
9+
hasMethodFilterOptions() {
10+
if (this.options) {
11+
for (const methodName of ObservableLibraryMethods) {
12+
if (this.options[methodName]) {
13+
return true;
14+
}
15+
}
16+
}
17+
return false;
18+
}
19+
20+
publish(publishObject: LocalForageObservableChange) {
21+
if (
22+
publishObject.success &&
23+
typeof this.subscriptionObserver.next === 'function'
24+
) {
25+
try {
26+
this.subscriptionObserver.next(publishObject);
27+
} catch (e) {
28+
/* */
29+
}
30+
} else if (
31+
publishObject.fail &&
32+
typeof this.subscriptionObserver.error === 'function'
33+
) {
34+
try {
35+
this.subscriptionObserver.error(publishObject);
36+
} catch (e) {
37+
/* */
38+
}
39+
}
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { LocalForageObservableWrapper } from './LocalForageObservableWrapper';
2+
import CrossTabObserver from './StorageEventObserver';
3+
4+
export interface LocalForageWithObservablePrivateProps
5+
extends LocalForageWithObservableMethods {
6+
_dbInfo: {
7+
name: string;
8+
storeName: string;
9+
};
10+
_baseMethods: {
11+
setItem: <T>(key: string, value: T) => Promise<T>;
12+
removeItem: (key: string) => Promise<void>;
13+
clear: () => Promise<void>;
14+
};
15+
_observables: {
16+
changeDetection: LocalForageObservableWrapper[];
17+
callDetection: LocalForageObservableWrapper[];
18+
crossTabChangeDetection?: boolean;
19+
crossTabObserver?: CrossTabObserver;
20+
};
21+
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
export var ObservableLibraryMethods = [
1+
export const ObservableLibraryMethods: Array<
2+
keyof LocalForageObservableMethodOptions
3+
> = [
24
'clear',
35
// 'getItem',
46
// 'iterate',
57
// 'key',
68
// 'keys',
79
// 'length',
810
'removeItem',
9-
'setItem'
11+
'setItem',
1012
];

0 commit comments

Comments
 (0)