-
Notifications
You must be signed in to change notification settings - Fork 24.8k
/
cache.ts
104 lines (94 loc) 路 2.64 KB
/
cache.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {JSACTION, JSNAMESPACE} from './property';
/**
* Map from jsaction annotation to a parsed map from event name to action name.
*/
const parseCache: {[key: string]: {[key: string]: string}} = {};
/**
* Reads the jsaction parser cache from the given DOM Element.
*
* @param element .
* @return Map from event to qualified name of the jsaction bound to it.
*/
export function get(element: Element): {[key: string]: string} {
// @ts-ignore
return element[JSACTION];
}
/**
* Writes the jsaction parser cache to the given DOM Element.
*
* @param element .
* @param actionMap Map from event to qualified name of the jsaction bound to
* it.
*/
export function set(element: Element, actionMap: {[key: string]: string}) {
// @ts-ignore
element[JSACTION] = actionMap;
}
/**
* Looks up the parsed action map from the source jsaction attribute value.
*
* @param text Unparsed jsaction attribute value.
* @return Parsed jsaction attribute value, if already present in the cache.
*/
export function getParsed(text: string): {[key: string]: string} | undefined {
return parseCache[text];
}
/**
* Inserts the parse result for the given source jsaction value into the cache.
*
* @param text Unparsed jsaction attribute value.
* @param parsed Attribute value parsed into the action map.
*/
export function setParsed(text: string, parsed: {[key: string]: string}) {
parseCache[text] = parsed;
}
/**
* Clears the jsaction parser cache from the given DOM Element.
*
* @param element .
*/
export function clear(element: Element) {
if (JSACTION in element) {
delete element[JSACTION];
}
}
/**
* Reads the cached jsaction namespace from the given DOM
* Element. Undefined means there is no cached value; null is a cached
* jsnamespace attribute that's absent.
*
* @param element .
* @return .
*/
export function getNamespace(element: Element): string | null | undefined {
// @ts-ignore
return element[JSNAMESPACE];
}
/**
* Writes the cached jsaction namespace to the given DOM Element. Null
* represents a jsnamespace attribute that's absent.
*
* @param element .
* @param jsnamespace .
*/
export function setNamespace(element: Element, jsnamespace: string | null) {
// @ts-ignore
element[JSNAMESPACE] = jsnamespace;
}
/**
* Clears the cached jsaction namespace from the given DOM Element.
*
* @param element .
*/
export function clearNamespace(element: Element) {
if (JSNAMESPACE in element) {
delete element[JSNAMESPACE];
}
}