@angular-wave/angular.ts 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -0
- package/.eslintrc.cjs +29 -0
- package/.github/workflows/playwright.yml +27 -0
- package/CHANGELOG.md +17974 -0
- package/CODE_OF_CONDUCT.md +3 -0
- package/CONTRIBUTING.md +246 -0
- package/DEVELOPERS.md +488 -0
- package/LICENSE +22 -0
- package/Makefile +31 -0
- package/README.md +115 -0
- package/RELEASE.md +98 -0
- package/SECURITY.md +16 -0
- package/TRIAGING.md +135 -0
- package/css/angular.css +22 -0
- package/dist/angular-ts.cjs.js +36843 -0
- package/dist/angular-ts.esm.js +36841 -0
- package/dist/angular-ts.umd.js +36848 -0
- package/dist/build/angular-animate.js +4272 -0
- package/dist/build/angular-aria.js +426 -0
- package/dist/build/angular-message-format.js +1072 -0
- package/dist/build/angular-messages.js +829 -0
- package/dist/build/angular-mocks.js +3757 -0
- package/dist/build/angular-parse-ext.js +1275 -0
- package/dist/build/angular-resource.js +911 -0
- package/dist/build/angular-route.js +1266 -0
- package/dist/build/angular-sanitize.js +891 -0
- package/dist/build/angular-touch.js +368 -0
- package/dist/build/angular.js +36600 -0
- package/e2e/unit.spec.ts +15 -0
- package/images/android-chrome-192x192.png +0 -0
- package/images/android-chrome-512x512.png +0 -0
- package/images/apple-touch-icon.png +0 -0
- package/images/favicon-16x16.png +0 -0
- package/images/favicon-32x32.png +0 -0
- package/images/favicon.ico +0 -0
- package/images/site.webmanifest +1 -0
- package/index.html +104 -0
- package/package.json +47 -0
- package/playwright.config.ts +78 -0
- package/public/circle.html +1 -0
- package/public/my_child_directive.html +1 -0
- package/public/my_directive.html +1 -0
- package/public/my_other_directive.html +1 -0
- package/public/test.html +1 -0
- package/rollup.config.js +31 -0
- package/src/animations/animateCache.js +55 -0
- package/src/animations/animateChildrenDirective.js +105 -0
- package/src/animations/animateCss.js +1139 -0
- package/src/animations/animateCssDriver.js +291 -0
- package/src/animations/animateJs.js +367 -0
- package/src/animations/animateJsDriver.js +67 -0
- package/src/animations/animateQueue.js +851 -0
- package/src/animations/animation.js +506 -0
- package/src/animations/module.js +779 -0
- package/src/animations/ngAnimateSwap.js +119 -0
- package/src/animations/rafScheduler.js +50 -0
- package/src/animations/shared.js +378 -0
- package/src/constants.js +20 -0
- package/src/core/animate.js +845 -0
- package/src/core/animateCss.js +73 -0
- package/src/core/animateRunner.js +195 -0
- package/src/core/attributes.js +199 -0
- package/src/core/cache.js +45 -0
- package/src/core/compile.js +4727 -0
- package/src/core/controller.js +225 -0
- package/src/core/exceptionHandler.js +63 -0
- package/src/core/filter.js +146 -0
- package/src/core/interpolate.js +442 -0
- package/src/core/interval.js +188 -0
- package/src/core/intervalFactory.js +57 -0
- package/src/core/location.js +1086 -0
- package/src/core/parser/parse.js +2562 -0
- package/src/core/parser/parse.md +13 -0
- package/src/core/q.js +746 -0
- package/src/core/rootScope.js +1596 -0
- package/src/core/sanitizeUri.js +85 -0
- package/src/core/sce.js +1161 -0
- package/src/core/taskTrackerFactory.js +125 -0
- package/src/core/timeout.js +121 -0
- package/src/core/urlUtils.js +187 -0
- package/src/core/utils.js +1349 -0
- package/src/directive/a.js +37 -0
- package/src/directive/attrs.js +283 -0
- package/src/directive/bind.js +51 -0
- package/src/directive/bind.md +142 -0
- package/src/directive/change.js +12 -0
- package/src/directive/change.md +25 -0
- package/src/directive/cloak.js +12 -0
- package/src/directive/cloak.md +24 -0
- package/src/directive/events.js +75 -0
- package/src/directive/events.md +166 -0
- package/src/directive/form.js +725 -0
- package/src/directive/init.js +15 -0
- package/src/directive/init.md +41 -0
- package/src/directive/input.js +1783 -0
- package/src/directive/list.js +46 -0
- package/src/directive/list.md +22 -0
- package/src/directive/ngClass.js +249 -0
- package/src/directive/ngController.js +64 -0
- package/src/directive/ngCsp.js +82 -0
- package/src/directive/ngIf.js +134 -0
- package/src/directive/ngInclude.js +217 -0
- package/src/directive/ngModel.js +1356 -0
- package/src/directive/ngModelOptions.js +509 -0
- package/src/directive/ngOptions.js +670 -0
- package/src/directive/ngRef.js +90 -0
- package/src/directive/ngRepeat.js +650 -0
- package/src/directive/ngShowHide.js +255 -0
- package/src/directive/ngSwitch.js +178 -0
- package/src/directive/ngTransclude.js +98 -0
- package/src/directive/non-bindable.js +11 -0
- package/src/directive/non-bindable.md +17 -0
- package/src/directive/script.js +30 -0
- package/src/directive/select.js +624 -0
- package/src/directive/style.js +25 -0
- package/src/directive/style.md +23 -0
- package/src/directive/validators.js +329 -0
- package/src/exts/aria.js +544 -0
- package/src/exts/messages.js +852 -0
- package/src/filters/filter.js +207 -0
- package/src/filters/filter.md +69 -0
- package/src/filters/filters.js +239 -0
- package/src/filters/json.md +16 -0
- package/src/filters/limit-to.js +43 -0
- package/src/filters/limit-to.md +19 -0
- package/src/filters/order-by.js +183 -0
- package/src/filters/order-by.md +83 -0
- package/src/index.js +13 -0
- package/src/injector.js +1034 -0
- package/src/jqLite.js +1117 -0
- package/src/loader.js +1320 -0
- package/src/public.js +215 -0
- package/src/routeToRegExp.js +41 -0
- package/src/services/anchorScroll.js +135 -0
- package/src/services/browser.js +321 -0
- package/src/services/cacheFactory.js +398 -0
- package/src/services/cookieReader.js +72 -0
- package/src/services/document.js +64 -0
- package/src/services/http.js +1537 -0
- package/src/services/httpBackend.js +206 -0
- package/src/services/log.js +160 -0
- package/src/services/templateRequest.js +139 -0
- package/test/angular.spec.js +2153 -0
- package/test/aria/aria.spec.js +1245 -0
- package/test/binding.spec.js +504 -0
- package/test/build-test.html +14 -0
- package/test/injector.spec.js +2327 -0
- package/test/jasmine/jasmine-5.1.2/boot0.js +65 -0
- package/test/jasmine/jasmine-5.1.2/boot1.js +133 -0
- package/test/jasmine/jasmine-5.1.2/jasmine-html.js +963 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.css +320 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.js +10824 -0
- package/test/jasmine/jasmine-5.1.2/jasmine_favicon.png +0 -0
- package/test/jasmine/jasmine-browser.json +17 -0
- package/test/jasmine/jasmine.json +9 -0
- package/test/jqlite.spec.js +2133 -0
- package/test/loader.spec.js +219 -0
- package/test/messages/messages.spec.js +1146 -0
- package/test/min-err.spec.js +174 -0
- package/test/mock-test.html +13 -0
- package/test/module-test.html +15 -0
- package/test/ng/anomate.spec.js +606 -0
- package/test/ng/cache-factor.spec.js +334 -0
- package/test/ng/compile.spec.js +17956 -0
- package/test/ng/controller-provider.spec.js +227 -0
- package/test/ng/cookie-reader.spec.js +98 -0
- package/test/ng/directive/a.spec.js +192 -0
- package/test/ng/directive/bind.spec.js +334 -0
- package/test/ng/directive/boolean.spec.js +136 -0
- package/test/ng/directive/change.spec.js +71 -0
- package/test/ng/directive/class.spec.js +858 -0
- package/test/ng/directive/click.spec.js +38 -0
- package/test/ng/directive/cloak.spec.js +44 -0
- package/test/ng/directive/constoller.spec.js +194 -0
- package/test/ng/directive/element-style.spec.js +92 -0
- package/test/ng/directive/event.spec.js +282 -0
- package/test/ng/directive/form.spec.js +1518 -0
- package/test/ng/directive/href.spec.js +143 -0
- package/test/ng/directive/if.spec.js +402 -0
- package/test/ng/directive/include.spec.js +828 -0
- package/test/ng/directive/init.spec.js +68 -0
- package/test/ng/directive/input.spec.js +3810 -0
- package/test/ng/directive/list.spec.js +170 -0
- package/test/ng/directive/model-options.spec.js +1008 -0
- package/test/ng/directive/model.spec.js +1905 -0
- package/test/ng/directive/non-bindable.spec.js +55 -0
- package/test/ng/directive/options.spec.js +3583 -0
- package/test/ng/directive/ref.spec.js +575 -0
- package/test/ng/directive/repeat.spec.js +1675 -0
- package/test/ng/directive/script.spec.js +52 -0
- package/test/ng/directive/scrset.spec.js +67 -0
- package/test/ng/directive/select.spec.js +2541 -0
- package/test/ng/directive/show-hide.spec.js +253 -0
- package/test/ng/directive/src.spec.js +157 -0
- package/test/ng/directive/style.spec.js +178 -0
- package/test/ng/directive/switch.spec.js +647 -0
- package/test/ng/directive/validators.spec.js +717 -0
- package/test/ng/document.spec.js +52 -0
- package/test/ng/filter/filter.spec.js +714 -0
- package/test/ng/filter/filters.spec.js +35 -0
- package/test/ng/filter/limit-to.spec.js +251 -0
- package/test/ng/filter/order-by.spec.js +891 -0
- package/test/ng/filter.spec.js +149 -0
- package/test/ng/http-backend.spec.js +398 -0
- package/test/ng/http.spec.js +4071 -0
- package/test/ng/interpolate.spec.js +642 -0
- package/test/ng/interval.spec.js +343 -0
- package/test/ng/location.spec.js +3488 -0
- package/test/ng/on.spec.js +229 -0
- package/test/ng/parse.spec.js +4655 -0
- package/test/ng/prop.spec.js +805 -0
- package/test/ng/q.spec.js +2904 -0
- package/test/ng/root-element.spec.js +16 -0
- package/test/ng/sanitize-uri.spec.js +249 -0
- package/test/ng/sce.spec.js +660 -0
- package/test/ng/scope.spec.js +3442 -0
- package/test/ng/template-request.spec.js +236 -0
- package/test/ng/timeout.spec.js +351 -0
- package/test/ng/url-utils.spec.js +156 -0
- package/test/ng/utils.spec.js +144 -0
- package/test/original-test.html +21 -0
- package/test/public.spec.js +34 -0
- package/test/sanitize/bing-html.spec.js +36 -0
- package/test/server/express.js +158 -0
- package/test/test-utils.js +11 -0
- package/tsconfig.json +17 -0
- package/types/angular.d.ts +138 -0
- package/types/global.d.ts +9 -0
- package/types/index.d.ts +2357 -0
- package/types/jqlite.d.ts +558 -0
- package/vite.config.js +14 -0
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import { createMap, extend, forEach, isUndefined, minErr } from "../core/utils";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @ngdoc service
|
|
5
|
+
* @name $cacheFactory
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @description
|
|
9
|
+
* Factory that constructs {@link $cacheFactory.Cache Cache} objects and gives access to
|
|
10
|
+
* them.
|
|
11
|
+
*
|
|
12
|
+
* ```js
|
|
13
|
+
*
|
|
14
|
+
* let cache = $cacheFactory('cacheId');
|
|
15
|
+
* expect($cacheFactory.get('cacheId')).toBe(cache);
|
|
16
|
+
* expect($cacheFactory.get('noSuchCacheId')).not.toBeDefined();
|
|
17
|
+
*
|
|
18
|
+
* cache.put("key", "value");
|
|
19
|
+
* cache.put("another key", "another value");
|
|
20
|
+
*
|
|
21
|
+
* // We've specified no options on creation
|
|
22
|
+
* expect(cache.info()).toEqual({id: 'cacheId', size: 2});
|
|
23
|
+
*
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
<example module="cacheExampleApp" name="cache-factory">
|
|
29
|
+
<file name="index.html">
|
|
30
|
+
<div ng-controller="CacheController">
|
|
31
|
+
<input ng-model="newCacheKey" placeholder="Key">
|
|
32
|
+
<input ng-model="newCacheValue" placeholder="Value">
|
|
33
|
+
<button ng-click="put(newCacheKey, newCacheValue)">Cache</button>
|
|
34
|
+
|
|
35
|
+
<p ng-if="keys.length">Cached Values</p>
|
|
36
|
+
<div ng-repeat="key in keys">
|
|
37
|
+
<span ng-bind="key"></span>
|
|
38
|
+
<span>: </span>
|
|
39
|
+
<b ng-bind="cache.get(key)"></b>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<p>Cache Info</p>
|
|
43
|
+
<div ng-repeat="(key, value) in cache.info()">
|
|
44
|
+
<span ng-bind="key"></span>
|
|
45
|
+
<span>: </span>
|
|
46
|
+
<b ng-bind="value"></b>
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
</file>
|
|
50
|
+
<file name="script.js">
|
|
51
|
+
angular.module('cacheExampleApp', []).
|
|
52
|
+
controller('CacheController', ['$scope', '$cacheFactory', function($scope, $cacheFactory) {
|
|
53
|
+
$scope.keys = [];
|
|
54
|
+
$scope.cache = $cacheFactory('cacheId');
|
|
55
|
+
$scope.put = function(key, value) {
|
|
56
|
+
if (angular.isUndefined($scope.cache.get(key))) {
|
|
57
|
+
$scope.keys.push(key);
|
|
58
|
+
}
|
|
59
|
+
$scope.cache.put(key, angular.isUndefined(value) ? null : value);
|
|
60
|
+
};
|
|
61
|
+
}]);
|
|
62
|
+
</file>
|
|
63
|
+
<file name="style.css">
|
|
64
|
+
p {
|
|
65
|
+
margin: 10px 0 3px;
|
|
66
|
+
}
|
|
67
|
+
</file>
|
|
68
|
+
</example>
|
|
69
|
+
*/
|
|
70
|
+
export function CacheFactoryProvider() {
|
|
71
|
+
this.$get = function () {
|
|
72
|
+
const caches = {};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @param {string} cacheId Name or id of the newly created cache.
|
|
76
|
+
* @param {object=} options Options object that specifies the cache behavior. Properties:
|
|
77
|
+
*
|
|
78
|
+
* - `{number=}` `capacity` — turns the cache into LRU cache.
|
|
79
|
+
*
|
|
80
|
+
* @returns {object} Newly created cache object with the following set of methods:
|
|
81
|
+
*
|
|
82
|
+
* - `{object}` `info()` — Returns id, size, and options of cache.
|
|
83
|
+
* - `{{*}}` `put({string} key, {*} value)` — Puts a new key-value pair into the cache and returns
|
|
84
|
+
* it.
|
|
85
|
+
* - `{{*}}` `get({string} key)` — Returns cached value for `key` or undefined for cache miss.
|
|
86
|
+
* - `{void}` `remove({string} key)` — Removes a key-value pair from the cache.
|
|
87
|
+
* - `{void}` `removeAll()` — Removes all cached values.
|
|
88
|
+
* - `{void}` `destroy()` — Removes references to this cache from $cacheFactory.
|
|
89
|
+
*/
|
|
90
|
+
function cacheFactory(cacheId, options) {
|
|
91
|
+
if (cacheId in caches) {
|
|
92
|
+
throw minErr("$cacheFactory")(
|
|
93
|
+
"iid",
|
|
94
|
+
"CacheId '{0}' is already taken!",
|
|
95
|
+
cacheId,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let size = 0;
|
|
100
|
+
let stats = extend({}, options, { id: cacheId });
|
|
101
|
+
let data = createMap();
|
|
102
|
+
const capacity = (options && options.capacity) || Number.MAX_VALUE;
|
|
103
|
+
let lruHash = createMap();
|
|
104
|
+
let freshEnd = null;
|
|
105
|
+
let staleEnd = null;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @ngdoc type
|
|
109
|
+
* @name $cacheFactory.Cache
|
|
110
|
+
*
|
|
111
|
+
* @description
|
|
112
|
+
* A cache object used to store and retrieve data, primarily used by
|
|
113
|
+
* {@link $templateRequest $templateRequest} and the {@link ng.directive:script script}
|
|
114
|
+
* directive to cache templates and other data.
|
|
115
|
+
*
|
|
116
|
+
* ```js
|
|
117
|
+
* angular.module('superCache')
|
|
118
|
+
* .factory('superCache', ['$cacheFactory', function($cacheFactory) {
|
|
119
|
+
* return $cacheFactory('super-cache');
|
|
120
|
+
* }]);
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* Example test:
|
|
124
|
+
*
|
|
125
|
+
* ```js
|
|
126
|
+
* it('should behave like a cache', inject(function(superCache) {
|
|
127
|
+
* superCache.put('key', 'value');
|
|
128
|
+
* superCache.put('another key', 'another value');
|
|
129
|
+
*
|
|
130
|
+
* expect(superCache.info()).toEqual({
|
|
131
|
+
* id: 'super-cache',
|
|
132
|
+
* size: 2
|
|
133
|
+
* });
|
|
134
|
+
*
|
|
135
|
+
* superCache.remove('another key');
|
|
136
|
+
* expect(superCache.get('another key')).toBeUndefined();
|
|
137
|
+
*
|
|
138
|
+
* superCache.removeAll();
|
|
139
|
+
* expect(superCache.info()).toEqual({
|
|
140
|
+
* id: 'super-cache',
|
|
141
|
+
* size: 0
|
|
142
|
+
* });
|
|
143
|
+
* }));
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
return (caches[cacheId] = {
|
|
147
|
+
/**
|
|
148
|
+
* @ngdoc method
|
|
149
|
+
* @name $cacheFactory.Cache#put
|
|
150
|
+
* @kind function
|
|
151
|
+
*
|
|
152
|
+
* @description
|
|
153
|
+
* Inserts a named entry into the {@link $cacheFactory.Cache Cache} object to be
|
|
154
|
+
* retrieved later, and incrementing the size of the cache if the key was not already
|
|
155
|
+
* present in the cache. If behaving like an LRU cache, it will also remove stale
|
|
156
|
+
* entries from the set.
|
|
157
|
+
*
|
|
158
|
+
* It will not insert undefined values into the cache.
|
|
159
|
+
*
|
|
160
|
+
* @param {string} key the key under which the cached data is stored.
|
|
161
|
+
* @param {*} value the value to store alongside the key. If it is undefined, the key
|
|
162
|
+
* will not be stored.
|
|
163
|
+
* @returns {*} the value stored.
|
|
164
|
+
*/
|
|
165
|
+
put(key, value) {
|
|
166
|
+
if (isUndefined(value)) return;
|
|
167
|
+
if (capacity < Number.MAX_VALUE) {
|
|
168
|
+
const lruEntry = lruHash[key] || (lruHash[key] = { key });
|
|
169
|
+
|
|
170
|
+
refresh(lruEntry);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (!(key in data)) size++;
|
|
174
|
+
data[key] = value;
|
|
175
|
+
|
|
176
|
+
if (size > capacity) {
|
|
177
|
+
this.remove(staleEnd.key);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return value;
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @ngdoc method
|
|
185
|
+
* @name $cacheFactory.Cache#get
|
|
186
|
+
* @kind function
|
|
187
|
+
*
|
|
188
|
+
* @description
|
|
189
|
+
* Retrieves named data stored in the {@link $cacheFactory.Cache Cache} object.
|
|
190
|
+
*
|
|
191
|
+
* @param {string} key the key of the data to be retrieved
|
|
192
|
+
* @returns {*} the value stored.
|
|
193
|
+
*/
|
|
194
|
+
get(key) {
|
|
195
|
+
if (capacity < Number.MAX_VALUE) {
|
|
196
|
+
const lruEntry = lruHash[key];
|
|
197
|
+
|
|
198
|
+
if (!lruEntry) return;
|
|
199
|
+
|
|
200
|
+
refresh(lruEntry);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return data[key];
|
|
204
|
+
},
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @ngdoc method
|
|
208
|
+
* @name $cacheFactory.Cache#remove
|
|
209
|
+
* @kind function
|
|
210
|
+
*
|
|
211
|
+
* @description
|
|
212
|
+
* Removes an entry from the {@link $cacheFactory.Cache Cache} object.
|
|
213
|
+
*
|
|
214
|
+
* @param {string} key the key of the entry to be removed
|
|
215
|
+
*/
|
|
216
|
+
remove(key) {
|
|
217
|
+
if (capacity < Number.MAX_VALUE) {
|
|
218
|
+
const lruEntry = lruHash[key];
|
|
219
|
+
|
|
220
|
+
if (!lruEntry) return;
|
|
221
|
+
|
|
222
|
+
if (lruEntry === freshEnd) freshEnd = lruEntry.p;
|
|
223
|
+
if (lruEntry === staleEnd) staleEnd = lruEntry.n;
|
|
224
|
+
link(lruEntry.n, lruEntry.p);
|
|
225
|
+
|
|
226
|
+
delete lruHash[key];
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (!(key in data)) return;
|
|
230
|
+
|
|
231
|
+
delete data[key];
|
|
232
|
+
size--;
|
|
233
|
+
},
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* @ngdoc method
|
|
237
|
+
* @name $cacheFactory.Cache#removeAll
|
|
238
|
+
* @kind function
|
|
239
|
+
*
|
|
240
|
+
* @description
|
|
241
|
+
* Clears the cache object of any entries.
|
|
242
|
+
*/
|
|
243
|
+
removeAll() {
|
|
244
|
+
data = createMap();
|
|
245
|
+
size = 0;
|
|
246
|
+
lruHash = createMap();
|
|
247
|
+
freshEnd = staleEnd = null;
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* @ngdoc method
|
|
252
|
+
* @name $cacheFactory.Cache#destroy
|
|
253
|
+
* @kind function
|
|
254
|
+
*
|
|
255
|
+
* @description
|
|
256
|
+
* Destroys the {@link $cacheFactory.Cache Cache} object entirely,
|
|
257
|
+
* removing it from the {@link $cacheFactory $cacheFactory} set.
|
|
258
|
+
*/
|
|
259
|
+
destroy() {
|
|
260
|
+
data = null;
|
|
261
|
+
stats = null;
|
|
262
|
+
lruHash = null;
|
|
263
|
+
delete caches[cacheId];
|
|
264
|
+
},
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* @ngdoc method
|
|
268
|
+
* @name $cacheFactory.Cache#info
|
|
269
|
+
* @kind function
|
|
270
|
+
*
|
|
271
|
+
* @description
|
|
272
|
+
* Retrieve information regarding a particular {@link $cacheFactory.Cache Cache}.
|
|
273
|
+
*
|
|
274
|
+
* @returns {object} an object with the following properties:
|
|
275
|
+
* <ul>
|
|
276
|
+
* <li>**id**: the id of the cache instance</li>
|
|
277
|
+
* <li>**size**: the number of entries kept in the cache instance</li>
|
|
278
|
+
* <li>**...**: any additional properties from the options object when creating the
|
|
279
|
+
* cache.</li>
|
|
280
|
+
* </ul>
|
|
281
|
+
*/
|
|
282
|
+
info() {
|
|
283
|
+
return extend({}, stats, { size });
|
|
284
|
+
},
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* makes the `entry` the freshEnd of the LRU linked list
|
|
289
|
+
*/
|
|
290
|
+
function refresh(entry) {
|
|
291
|
+
if (entry !== freshEnd) {
|
|
292
|
+
if (!staleEnd) {
|
|
293
|
+
staleEnd = entry;
|
|
294
|
+
} else if (staleEnd === entry) {
|
|
295
|
+
staleEnd = entry.n;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
link(entry.n, entry.p);
|
|
299
|
+
link(entry, freshEnd);
|
|
300
|
+
freshEnd = entry;
|
|
301
|
+
freshEnd.n = null;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* bidirectionally links two entries of the LRU linked list
|
|
307
|
+
*/
|
|
308
|
+
function link(nextEntry, prevEntry) {
|
|
309
|
+
if (nextEntry !== prevEntry) {
|
|
310
|
+
if (nextEntry) nextEntry.p = prevEntry; // p stands for previous, 'prev' didn't minify
|
|
311
|
+
if (prevEntry) prevEntry.n = nextEntry; // n stands for next, 'next' didn't minify
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* @ngdoc method
|
|
318
|
+
* @name $cacheFactory#info
|
|
319
|
+
*
|
|
320
|
+
* @description
|
|
321
|
+
* Get information about all the caches that have been created
|
|
322
|
+
*
|
|
323
|
+
* @returns {Object} - key-value map of `cacheId` to the result of calling `cache#info`
|
|
324
|
+
*/
|
|
325
|
+
cacheFactory.info = function () {
|
|
326
|
+
const info = {};
|
|
327
|
+
forEach(caches, (cache, cacheId) => {
|
|
328
|
+
info[cacheId] = cache.info();
|
|
329
|
+
});
|
|
330
|
+
return info;
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* @ngdoc method
|
|
335
|
+
* @name $cacheFactory#get
|
|
336
|
+
*
|
|
337
|
+
* @description
|
|
338
|
+
* Get access to a cache object by the `cacheId` used when it was created.
|
|
339
|
+
*
|
|
340
|
+
* @param {string} cacheId Name or id of a cache to access.
|
|
341
|
+
* @returns {object} Cache object identified by the cacheId or undefined if no such cache.
|
|
342
|
+
*/
|
|
343
|
+
cacheFactory.get = function (cacheId) {
|
|
344
|
+
return caches[cacheId];
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
return cacheFactory;
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* @name $templateCache
|
|
353
|
+
*
|
|
354
|
+
* @description
|
|
355
|
+
* `$templateCache` is a {@link $cacheFactory.Cache Cache object} created by the
|
|
356
|
+
* {@link ng.$cacheFactory $cacheFactory}.
|
|
357
|
+
*
|
|
358
|
+
* The first time a template is used, it is loaded in the template cache for quick retrieval. You
|
|
359
|
+
* can load templates directly into the cache in a `script` tag, by using {@link $templateRequest},
|
|
360
|
+
* or by consuming the `$templateCache` service directly.
|
|
361
|
+
*
|
|
362
|
+
* Adding via the `script` tag:
|
|
363
|
+
*
|
|
364
|
+
* ```html
|
|
365
|
+
* <script type="text/ng-template" id="templateId.html">
|
|
366
|
+
* <p>This is the content of the template</p>
|
|
367
|
+
* </script>
|
|
368
|
+
* ```
|
|
369
|
+
*
|
|
370
|
+
* **Note:** the `script` tag containing the template does not need to be included in the `head` of
|
|
371
|
+
* the document, but it must be a descendent of the {@link ng.$rootElement $rootElement} (e.g.
|
|
372
|
+
* element with {@link ngApp} attribute), otherwise the template will be ignored.
|
|
373
|
+
*
|
|
374
|
+
* Adding via the `$templateCache` service:
|
|
375
|
+
*
|
|
376
|
+
* ```js
|
|
377
|
+
* let myApp = angular.module('myApp', []);
|
|
378
|
+
* myApp.run(function($templateCache) {
|
|
379
|
+
* $templateCache.put('templateId.html', 'This is the content of the template');
|
|
380
|
+
* });
|
|
381
|
+
* ```
|
|
382
|
+
*
|
|
383
|
+
* To retrieve the template later, simply use it in your component:
|
|
384
|
+
* ```js
|
|
385
|
+
* myApp.component('myComponent', {
|
|
386
|
+
* templateUrl: 'templateId.html'
|
|
387
|
+
* });
|
|
388
|
+
* ```
|
|
389
|
+
*
|
|
390
|
+
* or get it via the `$templateCache` service:
|
|
391
|
+
* ```js
|
|
392
|
+
* $templateCache.get('templateId.html')
|
|
393
|
+
* ```
|
|
394
|
+
*
|
|
395
|
+
*/
|
|
396
|
+
export function TemplateCacheProvider() {
|
|
397
|
+
this.$get = ["$cacheFactory", ($cacheFactory) => $cacheFactory("templates")];
|
|
398
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { isUndefined } from "../core/utils";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @name $$cookieReader
|
|
5
|
+
* @requires $document
|
|
6
|
+
*
|
|
7
|
+
* @description
|
|
8
|
+
* This is a private service for reading cookies used by $http and ngCookies
|
|
9
|
+
*
|
|
10
|
+
* @return {Object} a key/value map of the current cookies
|
|
11
|
+
*/
|
|
12
|
+
export function $$CookieReader($document) {
|
|
13
|
+
const rawDocument = $document[0] || {};
|
|
14
|
+
let lastCookies = {};
|
|
15
|
+
let lastCookieString = "";
|
|
16
|
+
|
|
17
|
+
function safeGetCookie(rawDocument) {
|
|
18
|
+
try {
|
|
19
|
+
return rawDocument.cookie || "";
|
|
20
|
+
} catch (e) {
|
|
21
|
+
return "";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function safeDecodeURIComponent(str) {
|
|
26
|
+
try {
|
|
27
|
+
return decodeURIComponent(str);
|
|
28
|
+
} catch (e) {
|
|
29
|
+
return str;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return function () {
|
|
34
|
+
let cookieArray;
|
|
35
|
+
let cookie;
|
|
36
|
+
let i;
|
|
37
|
+
let index;
|
|
38
|
+
let name;
|
|
39
|
+
const currentCookieString = safeGetCookie(rawDocument);
|
|
40
|
+
|
|
41
|
+
if (currentCookieString !== lastCookieString) {
|
|
42
|
+
lastCookieString = currentCookieString;
|
|
43
|
+
cookieArray = lastCookieString.split("; ");
|
|
44
|
+
lastCookies = {};
|
|
45
|
+
|
|
46
|
+
// eslint-disable-next-line no-plusplus
|
|
47
|
+
for (i = 0; i < cookieArray.length; i++) {
|
|
48
|
+
cookie = cookieArray[i];
|
|
49
|
+
index = cookie.indexOf("=");
|
|
50
|
+
if (index > 0) {
|
|
51
|
+
// ignore nameless cookies
|
|
52
|
+
name = safeDecodeURIComponent(cookie.substring(0, index));
|
|
53
|
+
// the first value that is seen for a cookie is the most
|
|
54
|
+
// specific one. values for the same cookie name that
|
|
55
|
+
// follow are for less specific paths.
|
|
56
|
+
if (isUndefined(lastCookies[name])) {
|
|
57
|
+
lastCookies[name] = safeDecodeURIComponent(
|
|
58
|
+
cookie.substring(index + 1),
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return lastCookies;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
$$CookieReader.$inject = ["$document"];
|
|
69
|
+
|
|
70
|
+
export function CookieReaderProvider() {
|
|
71
|
+
this.$get = $$CookieReader;
|
|
72
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { jqLite } from "../jqLite";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @ngdoc service
|
|
5
|
+
* @name $document
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @description
|
|
9
|
+
* A {@link angular.element jQuery or jqLite} wrapper for the browser's `window.document` object.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
<example module="documentExample" name="document">
|
|
13
|
+
<file name="index.html">
|
|
14
|
+
<div ng-controller="ExampleController">
|
|
15
|
+
<p>$document title: <b ng-bind="title"></b></p>
|
|
16
|
+
<p>window.document title: <b ng-bind="windowTitle"></b></p>
|
|
17
|
+
</div>
|
|
18
|
+
</file>
|
|
19
|
+
<file name="script.js">
|
|
20
|
+
angular.module('documentExample', [])
|
|
21
|
+
.controller('ExampleController', ['$scope', '$document', function($scope, $document) {
|
|
22
|
+
$scope.title = $document[0].title;
|
|
23
|
+
$scope.windowTitle = angular.element(window.document)[0].title;
|
|
24
|
+
}]);
|
|
25
|
+
</file>
|
|
26
|
+
</example>
|
|
27
|
+
*/
|
|
28
|
+
export function $DocumentProvider() {
|
|
29
|
+
this.$get = [
|
|
30
|
+
function () {
|
|
31
|
+
return jqLite(window.document);
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @private
|
|
38
|
+
*
|
|
39
|
+
s * Listens for document visibility change and makes the current status accessible.
|
|
40
|
+
*/
|
|
41
|
+
export function $$IsDocumentHiddenProvider() {
|
|
42
|
+
this.$get = [
|
|
43
|
+
"$document",
|
|
44
|
+
"$rootScope",
|
|
45
|
+
function ($document, $rootScope) {
|
|
46
|
+
const doc = $document[0];
|
|
47
|
+
let hidden = doc && doc.hidden;
|
|
48
|
+
|
|
49
|
+
$document.on("visibilitychange", changeListener);
|
|
50
|
+
|
|
51
|
+
$rootScope.$on("$destroy", () => {
|
|
52
|
+
$document.off("visibilitychange", changeListener);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
function changeListener() {
|
|
56
|
+
hidden = doc.hidden;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return function () {
|
|
60
|
+
return hidden;
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
}
|