-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename reactive to responsive and add responsive event listener
- Loading branch information
1 parent
07fd1fe
commit 97f6810
Showing
11 changed files
with
166 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
export default class ResponsiveEvent { | ||
constructor() { | ||
this._listeners = new Set; | ||
|
||
window.addEventListener('resize', e => this._onResize(e)); | ||
} | ||
|
||
static global() { | ||
// allow to define a test ticker | ||
if (typeof globalThis !== 'undefined' && globalThis.chnobliResponsive) | ||
return globalThis.chnobliResponsive; | ||
|
||
if (typeof window === 'undefined') | ||
return null; | ||
|
||
if (typeof window.chnobliResponsive === 'undefined') | ||
window.chnobliResponsive = new ResponsiveEvent; | ||
return window.chnobliResponsive; | ||
} | ||
|
||
// fn({ width, height }, { remove() }) | ||
add(fn) { | ||
this._listeners.add(fn); | ||
|
||
return { | ||
remove: () => { | ||
this.remove(fn); | ||
} | ||
}; | ||
} | ||
|
||
remove(fn) { | ||
this._listeners.delete(fn); | ||
} | ||
|
||
_onResize(_e) { | ||
for (const fn of this._listeners) { | ||
fn({ | ||
width: window.innerWidth, | ||
height: window.innerHeight | ||
}, { | ||
remove: () => this.remove(fn) | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export default class TestResponsiveEvent { | ||
constructor() { | ||
this._listeners = new Set; | ||
|
||
globalThis.chnobliResponsive = this; | ||
} | ||
|
||
// fn({ width, height }, { remove() }) | ||
add(fn) { | ||
this._listeners.add(fn); | ||
|
||
return { | ||
remove: () => { | ||
this.remove(fn); | ||
} | ||
}; | ||
} | ||
|
||
remove(fn) { | ||
this._listeners.delete(fn); | ||
} | ||
|
||
resize(width, height) { | ||
for (const fn of this._listeners) { | ||
fn( | ||
{ width, height }, | ||
{ remove: () => this.remove(fn) } | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters