This repository has been archived by the owner on May 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathcache.js
120 lines (96 loc) · 3.15 KB
/
cache.js
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2013 Google Inc. All Rights Reserved.
/**
* @fileoverview Implements both a per element cache of its jsaction mapping
* and a global parse cache. The former avoids an attribute access per DOM node
* and the the latter avoids parsing the same jsaction annotation twice. In
* a typical application the same jsaction value would be used many times while
* the overall number of different values should be relatively small.
*/
goog.provide('jsaction.Cache');
goog.require('jsaction.Property');
/**
* Map from jsaction annotation to a parsed map from event name to action name.
* @private @const {!Object<!Object<string, string>>}
*/
jsaction.Cache.parseCache_ = {};
/**
* Reads the jsaction parser cache from the given DOM Element.
*
* @param {!Element} element .
* @return {!Object.<string, string>} Map from event to qualified name
* of the jsaction bound to it.
*/
jsaction.Cache.get = function(element) {
return element[jsaction.Property.JSACTION];
};
/**
* Writes the jsaction parser cache to the given DOM Element.
*
* @param {!Element} element .
* @param {!Object.<string, string>} actionMap Map from event to
* qualified name of the jsaction bound to it.
*/
jsaction.Cache.set = function(element, actionMap) {
element[jsaction.Property.JSACTION] = actionMap;
};
/**
* Looks up the parsed action map from the source jsaction attribute value.
*
* @param {string} text Unparsed jsaction attribute value.
* @return {!Object.<string, string>|undefined} Parsed jsaction attribute value,
* if already present in the cache.
*/
jsaction.Cache.getParsed = function(text) {
return jsaction.Cache.parseCache_[text];
};
/**
* Inserts the parse result for the given source jsaction value into the cache.
*
* @param {string} text Unparsed jsaction attribute value.
* @param {!Object.<string, string>} parsed Attribute value parsed into the
* action map.
*/
jsaction.Cache.setParsed = function(text, parsed) {
jsaction.Cache.parseCache_[text] = parsed;
};
/**
* Clears the jsaction parser cache from the given DOM Element.
*
* @param {!Element} element .
*/
jsaction.Cache.clear = function(element) {
if (jsaction.Property.JSACTION in element) {
delete element[jsaction.Property.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} element .
* @return {string|null|undefined} .
*/
jsaction.Cache.getNamespace = function(element) {
return element[jsaction.Property.JSNAMESPACE];
};
/**
* Writes the cached jsaction namespace to the given DOM Element. Null
* represents a jsnamespace attribute that's absent.
*
* @param {!Element} element .
* @param {?string} jsnamespace .
*/
jsaction.Cache.setNamespace = function(element, jsnamespace) {
element[jsaction.Property.JSNAMESPACE] = jsnamespace;
};
/**
* Clears the cached jsaction namespace from the given DOM Element.
*
* @param {!Element} element .
*/
jsaction.Cache.clearNamespace = function(element) {
if (jsaction.Property.JSNAMESPACE in element) {
delete element[jsaction.Property.JSNAMESPACE];
}
};