Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For two-way bindings, enforce consistency between .NET model and DOM …
- Loading branch information
1 parent
151ae52
commit f162ba1
Showing
28 changed files
with
925 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,34 @@ | ||
export class EventFieldInfo { | ||
constructor(public componentId: number, public fieldValue: string | boolean) { | ||
} | ||
|
||
public static fromEvent(componentId: number, event: Event): EventFieldInfo | null { | ||
const elem = event.target; | ||
if (elem instanceof Element) { | ||
const fieldData = getFormFieldData(elem); | ||
if (fieldData) { | ||
return new EventFieldInfo(componentId, fieldData.value); | ||
} | ||
} | ||
|
||
// This event isn't happening on a form field that we can reverse-map back to some incoming attribute | ||
return null; | ||
} | ||
} | ||
|
||
function getFormFieldData(elem: Element) { | ||
// The logic in here should be the inverse of the logic in BrowserRenderer's tryApplySpecialProperty. | ||
// That is, we're doing the reverse mapping, starting from an HTML property and reconstructing which | ||
// "special" attribute would have been mapped to that property. | ||
if (elem instanceof HTMLInputElement) { | ||
return (elem.type && elem.type.toLowerCase() === 'checkbox') | ||
? { value: elem.checked } | ||
: { value: elem.value }; | ||
} | ||
|
||
if (elem instanceof HTMLSelectElement || elem instanceof HTMLTextAreaElement) { | ||
return { value: elem.value }; | ||
} | ||
|
||
return null; | ||
} |
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.