Skip to content

Commit d733f2e

Browse files
authored
Refactor typeofEquals usage and remove isInstanceOfDomType (#80)
Closes #77 typeofEquals now takes a String and returns a bool, and instanceOfString is the canonical replacement for isInstanceOfDomType. Updates min SDK version and adds flavor to `setup-dart` step.
1 parent e58c223 commit d733f2e

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
lines changed

.github/workflows/test-package.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
- uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f
2828
with:
2929
sdk: ${{ matrix.sdk }}
30+
flavor: ${{ matrix.flavor }}
3031
- id: install
3132
name: Install dependencies
3233
run: dart pub get
@@ -37,9 +38,10 @@ jobs:
3738
run: dart analyze --fatal-infos
3839
if: always() && steps.install.outcome == 'success'
3940

40-
# Run tests on a matrix consisting of two dimensions:
41+
# Run tests on a matrix consisting of three dimensions:
4142
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
42-
# 2. release channel: dev
43+
# 2. release channel: main, dev
44+
# 3. flavor: raw
4345
test:
4446
needs: analyze
4547
runs-on: ${{ matrix.os }}
@@ -55,6 +57,7 @@ jobs:
5557
- uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f
5658
with:
5759
sdk: ${{ matrix.sdk }}
60+
flavor: ${{ matrix.flavor }}
5861
- id: install
5962
name: Install dependencies
6063
run: dart pub get

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.2.2-beta
2+
3+
- Updates SDK version minimum to 3.2.0-194.0.dev.
4+
- Removes `isInstanceOfDomType` as `dart:js_interop` now exposes
5+
`instanceOfString`.
6+
17
## 0.2.1-beta
28

39
- `helpers.dart`

lib/helpers.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,3 @@ external JSFunction get _audioConstructor;
5151
HTMLAudioElement createAudioElement() => _audioConstructor.callAsConstructor();
5252

5353
Element? querySelector(String selectors) => document.querySelector(selectors);
54-
55-
bool isInstanceOfDomType(JSObject? o, String domType) {
56-
if (o == null) return false;
57-
final constructor = globalContext[domType];
58-
if (constructor == null) return false;
59-
return o.instanceof(constructor as JSFunction).toDart;
60-
}

lib/src/helpers/events/providers.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ String _determineTransitionEventType(EventTarget e) {
612612
}
613613

614614
String _determineVisibilityChangeEventType(EventTarget e) {
615-
if (e.typeofEquals('undefined'.toJS).toDart) {
615+
if (e.typeofEquals('undefined')) {
616616
return 'visibilitychange';
617617
} else if (e.hasProperty('mozHidden'.toJS).toDart) {
618618
return 'mozvisibilitychange';

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
name: web
22
description: >-
33
Lightweight DOM and JS bindings built around JS static interop.
4-
version: 0.2.1-beta
4+
version: 0.2.2-beta
55

66
repository: https://github.com/dart-lang/web
77

88
environment:
9-
sdk: ">=3.2.0-157.0.dev <4.0.0"
9+
sdk: ">=3.2.0-194.0.dev <4.0.0"
1010

1111
dev_dependencies:
1212
args: ^2.4.0

test/helpers_test.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
@TestOn('browser')
66
library;
77

8+
import 'dart:js_interop';
9+
810
import 'package:test/test.dart';
911
import 'package:web/helpers.dart';
1012

1113
void main() {
12-
test('isInstanceOfDomType', () {
14+
test('instanceOfString works with package:web types', () {
1315
final div = document.createElement('div');
1416

15-
expect(isInstanceOfDomType(div, 'bob'), false);
16-
expect(isInstanceOfDomType(div, 'HTMLDivElement'), true);
17+
expect(div.instanceOfString('bob'), false);
18+
expect(div.instanceOfString('HTMLDivElement'), true);
1719
});
1820
}

0 commit comments

Comments
 (0)