-
-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LiveComponent] Allow binding LiveProp to URL query parameter
- Loading branch information
1 parent
23100d0
commit 68e4dd3
Showing
38 changed files
with
1,296 additions
and
90 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
13 changes: 13 additions & 0 deletions
13
src/LiveComponent/assets/dist/Component/plugins/QueryStringPlugin.d.ts
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,13 @@ | ||
import Component from '../index'; | ||
import { PluginInterface } from './PluginInterface'; | ||
interface QueryMapping { | ||
name: string; | ||
} | ||
export default class implements PluginInterface { | ||
private readonly mapping; | ||
constructor(mapping: { | ||
[p: string]: QueryMapping; | ||
}); | ||
attachToComponent(component: Component): void; | ||
} | ||
export {}; |
9 changes: 9 additions & 0 deletions
9
src/LiveComponent/assets/dist/Component/plugins/QueryStringPluging.d.ts
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,9 @@ | ||
import Component from '../index'; | ||
import { PluginInterface } from './PluginInterface'; | ||
export default class implements PluginInterface { | ||
private element; | ||
private mapping; | ||
attachToComponent(component: Component): void; | ||
private registerBindings; | ||
private updateUrl; | ||
} |
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,11 @@ | ||
export declare class UrlUtils extends URL { | ||
has(key: string): boolean; | ||
set(key: string, value: any): void; | ||
get(key: string): any | undefined; | ||
remove(key: string): void; | ||
private getData; | ||
private setData; | ||
} | ||
export declare class HistoryStrategy { | ||
static replace(url: URL): void; | ||
} |
31 changes: 31 additions & 0 deletions
31
src/LiveComponent/assets/src/Component/plugins/QueryStringPlugin.ts
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 @@ | ||
import Component from '../index'; | ||
import { PluginInterface } from './PluginInterface'; | ||
import { UrlUtils, HistoryStrategy } from '../../url_utils'; | ||
|
||
interface QueryMapping { | ||
/** | ||
* URL parameter name | ||
*/ | ||
name: string, | ||
} | ||
|
||
export default class implements PluginInterface { | ||
constructor(private readonly mapping: {[p: string]: QueryMapping}) {} | ||
|
||
attachToComponent(component: Component): void { | ||
component.on('render:finished', (component: Component) => { | ||
const urlUtils = new UrlUtils(window.location.href); | ||
const currentUrl = urlUtils.toString(); | ||
|
||
Object.entries(this.mapping).forEach(([prop, mapping]) => { | ||
const value = component.valueStore.get(prop); | ||
urlUtils.set(mapping.name, value); | ||
}); | ||
|
||
// Only update URL if it has changed | ||
if (currentUrl !== urlUtils.toString()) { | ||
HistoryStrategy.replace(urlUtils); | ||
} | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.