File tree Expand file tree Collapse file tree 4 files changed +12
-25
lines changed Expand file tree Collapse file tree 4 files changed +12
-25
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @sonnetjs/core" ,
3
- "version" : " 0.0.33 " ,
3
+ "version" : " 0.0.34 " ,
4
4
"files" : [
5
5
" dist"
6
6
],
Original file line number Diff line number Diff line change @@ -7,8 +7,6 @@ export interface SonnetComponentProps {
7
7
}
8
8
9
9
export default abstract class SonnetComponent {
10
- constructor ( ) { }
11
-
12
10
protected _id : string = '' ;
13
11
id ( id : string ) {
14
12
this . _id = id ;
@@ -27,26 +25,14 @@ export default abstract class SonnetComponent {
27
25
return this ;
28
26
}
29
27
30
- private _hashIdCache : string | undefined = undefined ;
28
+ private _hashIdCache ? : string ;
31
29
get hashId ( ) {
32
- if ( this . _hashIdCache ) {
33
- return this . _hashIdCache ;
34
- }
35
- const array = new Uint32Array ( 1 ) ;
36
- window . crypto . getRandomValues ( array ) ;
37
- const hash = array [ 0 ] . toString ( ) . substring ( 0 , 8 ) ;
38
- this . _hashIdCache = hash ;
39
- return hash ;
30
+ return this . _hashIdCache ??= window . crypto . getRandomValues ( new Uint32Array ( 1 ) ) [ 0 ] . toString ( ) . substring ( 0 , 8 ) ;
40
31
}
41
32
42
- private _parentCache : HTMLElement | undefined = undefined ;
33
+ private _parentCache ? : HTMLElement ;
43
34
get parent ( ) {
44
- if ( this . _parentCache ) {
45
- return this . _parentCache ;
46
- }
47
- const parent = document . getElementById ( this . hashId ) as HTMLElement ;
48
- this . _parentCache = parent ;
49
- return parent ;
35
+ return this . _parentCache ??= document . getElementById ( this . hashId ) as HTMLElement ;
50
36
}
51
37
52
38
rerender ( querySelector : string ) {
Original file line number Diff line number Diff line change @@ -16,8 +16,6 @@ export class SonnetApp {
16
16
private _isInitialized : boolean = false ;
17
17
private _mountedId : string = '' ;
18
18
19
- constructor ( ) { }
20
-
21
19
get component ( ) {
22
20
return this . _component ;
23
21
}
Original file line number Diff line number Diff line change @@ -11,22 +11,25 @@ interface Component<T> {
11
11
script ?: ( ) => void ;
12
12
}
13
13
14
+ const EMPTY_HEAD = 'head(){return""}' ;
15
+ const EMPTY_SCRIPT = 'script(){}' ;
16
+
14
17
export function $component < T > ( component : Component < T > ) {
15
18
return ( args ?: T ) => {
16
19
const instance = new component ( args ) ;
17
20
if ( isBrowser ( ) ) {
18
21
// head tags
19
- if ( component . head && component . head . toString ( ) !== 'head(){return""}' ) {
22
+ if ( component . head && component . head . toString ( ) !== EMPTY_HEAD ) {
20
23
event . once < SonnetHead > ( 'head' , component . head as ( ) => SonnetHead ) ;
21
24
}
22
- if ( instance . head && instance . head . toString ( ) !== 'head(){return""}' ) {
25
+ if ( instance . head && instance . head . toString ( ) !== EMPTY_HEAD ) {
23
26
event . on < SonnetHead > ( 'head' , instance . head . bind ( instance ) ) ;
24
27
}
25
28
// scripts
26
- if ( component . script && component . script . toString ( ) !== 'script(){}' ) {
29
+ if ( component . script && component . script . toString ( ) !== EMPTY_SCRIPT ) {
27
30
event . once ( 'script' , component . script ) ;
28
31
}
29
- if ( instance . script && instance . script . toString ( ) !== 'script(){}' ) {
32
+ if ( instance . script && instance . script . toString ( ) !== EMPTY_SCRIPT ) {
30
33
event . on ( 'script' , instance . script . bind ( instance ) ) ;
31
34
}
32
35
}
You can’t perform that action at this time.
0 commit comments