vsn 0.1.129 → 0.1.131

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.
Files changed (56) hide show
  1. package/demo/examples/cascading-function-sheets.html +2 -2
  2. package/demo/examples/events.html +1 -1
  3. package/demo/examples/persist.html +17 -0
  4. package/demo/resources/xhr-persist.html +40 -0
  5. package/demo/vsn.js +2 -2
  6. package/dist/AST/ClassNode.js +2 -0
  7. package/dist/AST/ClassNode.js.map +1 -1
  8. package/dist/AST/FunctionNode.js +8 -1
  9. package/dist/AST/FunctionNode.js.map +1 -1
  10. package/dist/AST/IndexNode.js +7 -1
  11. package/dist/AST/IndexNode.js.map +1 -1
  12. package/dist/AST.d.ts +20 -0
  13. package/dist/AST.js +82 -23
  14. package/dist/AST.js.map +1 -1
  15. package/dist/Attribute.js.map +1 -1
  16. package/dist/DOM/AbstractDOM.d.ts +1 -0
  17. package/dist/DOM/AbstractDOM.js +114 -91
  18. package/dist/DOM/AbstractDOM.js.map +1 -1
  19. package/dist/Registry.d.ts +1 -2
  20. package/dist/Registry.js +15 -16
  21. package/dist/Registry.js.map +1 -1
  22. package/dist/Tag.d.ts +1 -0
  23. package/dist/Tag.js +7 -0
  24. package/dist/Tag.js.map +1 -1
  25. package/dist/attributes/PersistAttribute.d.ts +15 -0
  26. package/dist/attributes/PersistAttribute.js +215 -0
  27. package/dist/attributes/PersistAttribute.js.map +1 -0
  28. package/dist/attributes/_imports.d.ts +1 -0
  29. package/dist/attributes/_imports.js +3 -1
  30. package/dist/attributes/_imports.js.map +1 -1
  31. package/dist/version.d.ts +1 -1
  32. package/dist/version.js +1 -1
  33. package/dist/vsn.d.ts +0 -1
  34. package/dist/vsn.js +1 -3
  35. package/dist/vsn.js.map +1 -1
  36. package/package.json +1 -1
  37. package/src/AST/ClassNode.ts +2 -0
  38. package/src/AST/FunctionNode.ts +8 -1
  39. package/src/AST/IndexNode.ts +4 -0
  40. package/src/AST.ts +72 -24
  41. package/src/Attribute.ts +0 -1
  42. package/src/DOM/AbstractDOM.ts +17 -3
  43. package/src/Registry.ts +6 -9
  44. package/src/Tag.ts +4 -0
  45. package/src/attributes/PersistAttribute.ts +83 -0
  46. package/src/attributes/_imports.ts +1 -0
  47. package/src/version.ts +1 -1
  48. package/src/vsn.ts +0 -1
  49. package/test/AST/FunctionNode.spec.ts +9 -0
  50. package/test/AST.spec.ts +6 -8
  51. package/test/Controller.spec.ts +15 -16
  52. package/dist/SimplePromise.d.ts +0 -42
  53. package/dist/SimplePromise.js +0 -258
  54. package/dist/SimplePromise.js.map +0 -1
  55. package/src/SimplePromise.ts +0 -219
  56. package/test/SimplePromise.spec.ts +0 -271
package/src/Attribute.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import {Tag} from "./Tag";
2
- import {VisionHelper} from "./helpers/VisionHelper";
3
2
  import {EventDispatcher} from "./EventDispatcher";
4
3
  import {Modifiers} from "./Modifiers";
5
4
 
@@ -177,6 +177,21 @@ export abstract class AbstractDOM extends EventDispatcher {
177
177
  }
178
178
  }
179
179
 
180
+ public getTagsFromParent(parent: Node, includeParent: boolean = true) {
181
+ const tags: Tag[] = [];
182
+ if (includeParent) {
183
+ if (parent[Tag.TaggedVariable]) {
184
+ tags.push(parent[Tag.TaggedVariable]);
185
+ }
186
+ }
187
+
188
+ for (const ele of Array.from(parent.childNodes)) {
189
+ tags.push(...this.getTagsFromParent(ele, true));
190
+ }
191
+
192
+ return tags;
193
+ }
194
+
180
195
  public async mutation(mutations: MutationRecord[]) {
181
196
  for (const mutation of mutations) {
182
197
  let tag: Tag = await this.getTagForElement(mutation.target as HTMLElement);
@@ -190,9 +205,8 @@ export abstract class AbstractDOM extends EventDispatcher {
190
205
  }
191
206
 
192
207
  for (const ele of Array.from(mutation.removedNodes)) {
193
- const toRemove: Tag = await this.getTagForElement(ele as HTMLElement);
194
- if (toRemove) {
195
- toRemove.deconstruct();
208
+ for (const tag of this.getTagsFromParent(ele)) {
209
+ tag.deconstruct();
196
210
  }
197
211
  }
198
212
  }
package/src/Registry.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import {EventDispatcher} from "./EventDispatcher";
2
- import {IDeferred, IPromise, SimplePromise} from "./SimplePromise";
3
2
  import {ClassNode} from "./AST/ClassNode";
4
3
 
5
4
  export function register(store: string, key: string = null, setup: () => void = null) {
@@ -28,11 +27,10 @@ export class RegistryStore<T = any> extends EventDispatcher {
28
27
  this.dispatch(`registered:${key}`, item);
29
28
  }
30
29
 
31
- get(key: string): IPromise<any> {
32
- const deferred: IDeferred<any> = SimplePromise.defer();
33
-
34
- if (!!this.store[key]) {
35
- deferred.resolve(this.store[key]);
30
+ get(key: string): Promise<any> {
31
+ return new Promise((resolve, reject) => {
32
+ if (!!this.store[key]) {
33
+ resolve(this.store[key]);
36
34
  } else {
37
35
  console.warn(`Waiting for ${key} to be registered.`);
38
36
  this.timeouts[key] = setTimeout(() => {
@@ -40,11 +38,10 @@ export class RegistryStore<T = any> extends EventDispatcher {
40
38
  }, 5000);
41
39
  this.once(`registered:${key}`, (cls) => {
42
40
  clearTimeout(this.timeouts[key]);
43
- deferred.resolve(cls);
41
+ resolve(cls);
44
42
  })
45
43
  }
46
-
47
- return deferred.promise;
44
+ });
48
45
  }
49
46
 
50
47
  getSynchronous(key: string) {
package/src/Tag.ts CHANGED
@@ -89,6 +89,10 @@ export class Tag extends DOMObject {
89
89
  return this._meta;
90
90
  }
91
91
 
92
+ public get state(): TagState {
93
+ return this._state;
94
+ }
95
+
92
96
  protected onAttributeStateChange(event) {
93
97
  if (event.previouseState === AttributeState.Deferred) // @todo: what is this?
94
98
  this._nonDeferredAttributes.length = 0;
@@ -0,0 +1,83 @@
1
+ import {Registry} from "../Registry";
2
+ import {Attribute} from "../Attribute";
3
+ import {TagState} from "../Tag";
4
+
5
+
6
+ export interface IPersistedValue {
7
+ attribute: string,
8
+ value: string
9
+ }
10
+
11
+ @Registry.attribute('vsn-persist')
12
+ export class PersistAttribute extends Attribute {
13
+ public static readonly persistedValues: Map<string, Map<string, string | string[]>> = new Map<string, Map<string, string | string[]>>();
14
+ public static readonly canDefer: boolean = true;
15
+
16
+ protected valueKeys: string[] = [];
17
+
18
+ public async extract() {
19
+ this.valueKeys = this.getAttributeValue().split(' ').map((v: string) => v.trim()).filter((v: string) => v.length > 0);
20
+ await super.extract();
21
+ }
22
+
23
+ public async connect() {
24
+ const elementId = this.tag.element.id;
25
+
26
+ if (!elementId)
27
+ throw new Error('vsn-persist requires an id attribute on the element');
28
+
29
+ const persistedValues = PersistAttribute.getPersistedValueStore(elementId);
30
+ for (const key of this.valueKeys) {
31
+ if (persistedValues.has(key)) {
32
+ if (key === '@class') {
33
+ const classes = persistedValues.get(key);
34
+ this.tag.element.classList.remove(...Array.from(this.tag.element.classList));
35
+ this.tag.element.classList.add(...classes);
36
+ } else if (key.startsWith('@')) {
37
+ this.tag.element.setAttribute(key.substring(1), persistedValues.get(key) as string);
38
+ if (this.tag.isInput) {
39
+ this.tag.once('$built', () => {
40
+ this.tag.element.dispatchEvent(new Event('input'));
41
+ });
42
+ }
43
+ } else {
44
+
45
+ }
46
+ }
47
+ }
48
+ await super.connect();
49
+ }
50
+
51
+ public mutate(mutation: MutationRecord) {
52
+ if (this.tag.state !== TagState.Built)
53
+ return;
54
+
55
+ this.updateFrom();
56
+ }
57
+
58
+ protected updateFrom() {
59
+ const elementId = this.tag.element.id;
60
+ const persistedValues = PersistAttribute.getPersistedValueStore(elementId);
61
+
62
+ for (const key of this.valueKeys) {
63
+ if (key === '@class') {
64
+ const classes = Array.from(this.tag.element.classList);
65
+ persistedValues.set(key, classes);
66
+ } else if (key.startsWith('@')) {
67
+ persistedValues.set(key, this.tag.element.getAttribute(key.substring(1)));
68
+ if (this.tag.isInput) {
69
+ this.tag.dispatch('input');
70
+ }
71
+ } else {
72
+
73
+ }
74
+ }
75
+ }
76
+
77
+ public static getPersistedValueStore(elementId: string) {
78
+ if (!PersistAttribute.persistedValues.has(elementId))
79
+ PersistAttribute.persistedValues.set(elementId, new Map<string, string>());
80
+
81
+ return PersistAttribute.persistedValues.get(elementId);
82
+ }
83
+ }
@@ -16,6 +16,7 @@ export {ListItemModel} from "./ListItemModel";
16
16
  export {ModelAttribute} from "./ModelAttribute";
17
17
  export {Name} from "./Name";
18
18
  export {On} from "./On";
19
+ export {PersistAttribute} from "./PersistAttribute";
19
20
  export {Referenced} from "./Referenced";
20
21
  export {RootAttribute} from "./RootAttribute";
21
22
  export {ScopeAttribute} from "./ScopeAttribute";
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.1.129';
1
+ export const VERSION = '0.1.131';
2
2
 
package/src/vsn.ts CHANGED
@@ -101,6 +101,5 @@ export {Model} from './Model';
101
101
  export {Service} from './Service';
102
102
  export {EventDispatcher} from './EventDispatcher';
103
103
  export {MessageList} from './MessageList';
104
- export {SimplePromise} from './SimplePromise';
105
104
  export {Tag} from './Tag';
106
105
  export const vision: Vision = Vision.instance;
@@ -11,4 +11,13 @@ describe('FunctionNode', () => {
11
11
  const v = await tree.evaluate(scope, null, null);
12
12
  expect(v).toBe(3);
13
13
  });
14
+
15
+ it("should take a multitude of arguments", async () => {
16
+ const tree = new Tree(`func add(a_int, a_dict, a_arr) { log(a_int, a_dict['a'], a_arr[0]); return a_int + a_dict['a'] + a_arr[0]; }; add(1, {'a':1, 'b': 2}, [1]);`);
17
+ const scope = new Scope();
18
+ await tree.prepare(scope, null, null);
19
+ expect(scope.get('add')).toBeDefined();
20
+ const v = await tree.evaluate(scope, null, null);
21
+ expect(v).toBe(3);
22
+ });
14
23
  });
package/test/AST.spec.ts CHANGED
@@ -2,7 +2,6 @@ import {WrappedArray} from '../src/Scope/WrappedArray';
2
2
  import {Scope} from "../src/Scope";
3
3
  import {Tree} from "../src/AST";
4
4
  import {DOM} from "../src/DOM";
5
- import {IDeferred, SimplePromise} from "../src/SimplePromise";
6
5
 
7
6
  describe('Tree', () => {
8
7
  let scope: Scope = null,
@@ -242,14 +241,13 @@ describe('Tree', () => {
242
241
 
243
242
  it("should be able to block properly with promises", async () => {
244
243
  scope.set('blockingFunction', async (num, toAdd, fin: boolean = false) => {
245
- const deferred: IDeferred<number> = SimplePromise.defer();
246
- expect(scope.get('test')).toBe(num);
244
+ return new Promise((resolve, reject) => {
245
+ expect(scope.get('test')).toBe(num);
247
246
 
248
- setTimeout(() => {
249
- deferred.resolve(num + toAdd);
250
- }, 1);
251
-
252
- return deferred.promise;
247
+ setTimeout(() => {
248
+ resolve(num + toAdd);
249
+ }, 1);
250
+ });
253
251
  });
254
252
 
255
253
  let tree: Tree = new Tree(`
@@ -1,6 +1,5 @@
1
1
  import {Controller} from '../src/Controller';
2
2
  import {DOM} from "../src/DOM";
3
- import {SimplePromise} from "../src/SimplePromise";
4
3
  import {Registry} from "../src/Registry";
5
4
  import {property} from "../src/Scope/properties/Property";
6
5
  import {Property, Scope, Tag} from "../src/vsn";
@@ -31,21 +30,21 @@ describe('Controller', () => {
31
30
  <div id="controller" vsn-controller:test="ControllerTestController" vsn-set:test.test="notTest" vsn-bind="test.test"></div>
32
31
  `;
33
32
  const dom = new DOM(document.body);
34
- const deferred = SimplePromise.defer();
35
- dom.once('built', async () => {
36
- const tag = await dom.exec('#controller');
37
- expect(tag).toBeInstanceOf(Tag);
38
- expect(tag.scope).toBeInstanceOf(Scope);
39
- /*
40
- expect(tag.scope.keys).toEqual(['test']);
41
- expect(tag.scope.get('test').wrapped).toBeInstanceOf(TestController);
42
- expect(await tag.exec('test.isValid()')).toBe(false);
43
- expect(await tag.exec('test.test')).toBe('notTest');
44
- await tag.exec('test.test = "test"');
45
- expect(await tag.exec('test.isValid()')).toBe(true);
46
- */
47
- deferred.resolve();
33
+ await new Promise((resolve, reject) => {
34
+ dom.once('built', async () => {
35
+ const tag = await dom.exec('#controller');
36
+ expect(tag).toBeInstanceOf(Tag);
37
+ expect(tag.scope).toBeInstanceOf(Scope);
38
+ /*
39
+ expect(tag.scope.keys).toEqual(['test']);
40
+ expect(tag.scope.get('test').wrapped).toBeInstanceOf(TestController);
41
+ expect(await tag.exec('test.isValid()')).toBe(false);
42
+ expect(await tag.exec('test.test')).toBe('notTest');
43
+ await tag.exec('test.test = "test"');
44
+ expect(await tag.exec('test.isValid()')).toBe(true);
45
+ */
46
+ resolve(null);
47
+ });
48
48
  });
49
- await deferred.promise;
50
49
  });
51
50
  });
@@ -1,42 +0,0 @@
1
- import { EventDispatcher } from "./EventDispatcher";
2
- export interface IDeferred<T> {
3
- [key: string]: any;
4
- promise: SimplePromise<T>;
5
- resolve(result?: T): void;
6
- reject(reason: string): void;
7
- }
8
- export declare type TResolve<T> = (result: T) => void;
9
- export declare type TReject = (reason: string) => void;
10
- export declare type TResult<T> = T | string | null;
11
- export declare enum EPromiseStates {
12
- PENDING = 0,
13
- FULFILLED = 1,
14
- REJECTED = 2
15
- }
16
- export interface IPromise<T> extends EventDispatcher {
17
- state: EPromiseStates;
18
- result: TResult<T>;
19
- then<X = T>(success?: (result?: T) => X, error?: (reason?: string) => string): IPromise<X>;
20
- catch(onRejected: (reason: string) => string): IPromise<string>;
21
- finally<X = T>(finallyCallback: (result: T | string) => X | string): IPromise<X>;
22
- }
23
- export declare function noop<T = any>(result?: T): T;
24
- export declare class SimplePromise<T> extends EventDispatcher implements IPromise<T> {
25
- protected _state: EPromiseStates;
26
- protected _result: TResult<T>;
27
- private promiseClass;
28
- constructor(executor: (resolve: TResolve<T>, reject: TReject) => void);
29
- get state(): EPromiseStates;
30
- get result(): TResult<T>;
31
- static defer<T>(): IDeferred<T>;
32
- static resolve<T>(result?: T): IPromise<T>;
33
- static reject(reason: string): IPromise<void>;
34
- static all<T>(iter: IPromise<T>[]): IPromise<T[]>;
35
- static poolResults<T>(iter: IPromise<T>[], deferred: IDeferred<T[]>): void;
36
- static race<T>(iter: IPromise<T>[]): IPromise<T>;
37
- then<X = T>(success?: (result: T) => X, error?: (reason: string) => string): IPromise<X>;
38
- catch(onRejected: (reason: string) => string): IPromise<string>;
39
- finally<X = T>(finallyCallback: (result: T | string) => X | string): IPromise<X>;
40
- protected _resolve(result: T): void;
41
- protected _reject(reason: string): void;
42
- }
@@ -1,258 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __values = (this && this.__values) || function(o) {
18
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
19
- if (m) return m.call(o);
20
- if (o && typeof o.length === "number") return {
21
- next: function () {
22
- if (o && i >= o.length) o = void 0;
23
- return { value: o && o[i++], done: !o };
24
- }
25
- };
26
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.SimplePromise = exports.noop = exports.EPromiseStates = void 0;
30
- var EventDispatcher_1 = require("./EventDispatcher");
31
- var EPromiseStates;
32
- (function (EPromiseStates) {
33
- EPromiseStates[EPromiseStates["PENDING"] = 0] = "PENDING";
34
- EPromiseStates[EPromiseStates["FULFILLED"] = 1] = "FULFILLED";
35
- EPromiseStates[EPromiseStates["REJECTED"] = 2] = "REJECTED";
36
- })(EPromiseStates = exports.EPromiseStates || (exports.EPromiseStates = {}));
37
- function noop(result) { return result; }
38
- exports.noop = noop;
39
- var SimplePromise = /** @class */ (function (_super) {
40
- __extends(SimplePromise, _super);
41
- function SimplePromise(executor) {
42
- var _this = _super.call(this) || this;
43
- _this._result = null;
44
- _this._state = EPromiseStates.PENDING;
45
- _this.promiseClass = (Object.getPrototypeOf(_this).constructor);
46
- try {
47
- executor(_this._resolve.bind(_this), _this._reject.bind(_this));
48
- }
49
- catch (e) {
50
- _this._reject(e);
51
- }
52
- return _this;
53
- }
54
- Object.defineProperty(SimplePromise.prototype, "state", {
55
- get: function () {
56
- return this._state;
57
- },
58
- enumerable: false,
59
- configurable: true
60
- });
61
- Object.defineProperty(SimplePromise.prototype, "result", {
62
- get: function () {
63
- return this._result;
64
- },
65
- enumerable: false,
66
- configurable: true
67
- });
68
- SimplePromise.defer = function () {
69
- var promise = new SimplePromise(function (res, rej) { });
70
- return {
71
- promise: promise,
72
- resolve: promise._resolve.bind(promise),
73
- reject: promise._reject.bind(promise)
74
- };
75
- };
76
- /*
77
- * Returns a Promise object that is resolved with the given value. If the value is a thenable (i.e. has a then
78
- * method), the returned promise will "follow" that thenable, adopting its eventual state; otherwise the returned
79
- * promise will be fulfilled with the value. Generally, if you don't know if a value is a promise or not,
80
- * Promise.resolve(value) it instead and work with the return value as a promise.
81
- */
82
- SimplePromise.resolve = function (result) {
83
- return new SimplePromise(function (resolve) {
84
- if (result instanceof SimplePromise) {
85
- result.then(function (innerResult) {
86
- resolve(innerResult);
87
- });
88
- }
89
- else {
90
- resolve(result);
91
- }
92
- });
93
- };
94
- /*
95
- * Returns a Promise object that is rejected with the given reason.
96
- */
97
- SimplePromise.reject = function (reason) {
98
- return new SimplePromise(function (resolve, reject) {
99
- reject(reason);
100
- });
101
- };
102
- /*
103
- * Returns a promise that either fulfills when all of the promises in the iterable argument have fulfilled or
104
- * rejects as soon as one of the promises in the iterable argument rejects. If the returned promise fulfills, it is
105
- * fulfilled with an array of the values from the fulfilled promises in the same order as defined in the iterable.
106
- * If the returned promise rejects, it is rejected with the reason from the first promise in the iterable that
107
- * rejected. This method can be useful for aggregating results of multiple promises.
108
- */
109
- SimplePromise.all = function (iter) {
110
- var e_1, _a;
111
- var deferred = SimplePromise.defer();
112
- var done = true;
113
- try {
114
- for (var iter_1 = __values(iter), iter_1_1 = iter_1.next(); !iter_1_1.done; iter_1_1 = iter_1.next()) {
115
- var promise = iter_1_1.value;
116
- if (promise.state == EPromiseStates.PENDING) {
117
- done = false;
118
- promise.once('fulfilled', function (result) {
119
- SimplePromise.poolResults(iter, deferred);
120
- });
121
- promise.once('rejected', function (reason) {
122
- deferred.reject(reason);
123
- });
124
- }
125
- else if (promise.state == EPromiseStates.REJECTED) {
126
- deferred.reject(promise.result);
127
- done = false;
128
- break;
129
- }
130
- }
131
- }
132
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
133
- finally {
134
- try {
135
- if (iter_1_1 && !iter_1_1.done && (_a = iter_1.return)) _a.call(iter_1);
136
- }
137
- finally { if (e_1) throw e_1.error; }
138
- }
139
- if (done)
140
- SimplePromise.poolResults(iter, deferred);
141
- return deferred.promise;
142
- };
143
- SimplePromise.poolResults = function (iter, deferred) {
144
- var e_2, _a;
145
- var done = true;
146
- var results = [];
147
- try {
148
- for (var iter_2 = __values(iter), iter_2_1 = iter_2.next(); !iter_2_1.done; iter_2_1 = iter_2.next()) {
149
- var p = iter_2_1.value;
150
- if (p.state === EPromiseStates.REJECTED) {
151
- deferred.reject(p.result);
152
- break;
153
- }
154
- else if (p.state === EPromiseStates.PENDING) {
155
- done = false;
156
- }
157
- results.push(p.result);
158
- }
159
- }
160
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
161
- finally {
162
- try {
163
- if (iter_2_1 && !iter_2_1.done && (_a = iter_2.return)) _a.call(iter_2);
164
- }
165
- finally { if (e_2) throw e_2.error; }
166
- }
167
- if (done)
168
- deferred.resolve(results);
169
- };
170
- /*
171
- * Returns a promise that fulfills or rejects as soon as one of the promises in the iterable fulfills or rejects,
172
- * with the value or reason from that promise.
173
- */
174
- SimplePromise.race = function (iter) {
175
- var e_3, _a;
176
- var deferred = SimplePromise.defer();
177
- try {
178
- for (var iter_3 = __values(iter), iter_3_1 = iter_3.next(); !iter_3_1.done; iter_3_1 = iter_3.next()) {
179
- var promise = iter_3_1.value;
180
- promise.once('fulfilled', function (result) {
181
- deferred.resolve(result);
182
- });
183
- promise.once('rejected', function (reason) {
184
- deferred.reject(reason);
185
- });
186
- }
187
- }
188
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
189
- finally {
190
- try {
191
- if (iter_3_1 && !iter_3_1.done && (_a = iter_3.return)) _a.call(iter_3);
192
- }
193
- finally { if (e_3) throw e_3.error; }
194
- }
195
- return deferred.promise;
196
- };
197
- /*
198
- * Appends fulfillment and rejection handlers to the promise, and returns a new promise resolving to the return
199
- * value of the called handler, or to its original settled value if the promise was not handled (i.e. if the
200
- * relevant handler onFulfilled or onRejected is not a function).
201
- */
202
- SimplePromise.prototype.then = function (success, error) {
203
- var _this = this;
204
- return new this.promiseClass(function (resolve, reject) {
205
- if (_this.state === EPromiseStates.FULFILLED) {
206
- if (success)
207
- resolve(success(_this.result));
208
- }
209
- else if (_this.state === EPromiseStates.REJECTED) {
210
- if (error)
211
- reject(error(_this.result));
212
- }
213
- else {
214
- _this.once('fulfilled', function (result) {
215
- if (success)
216
- resolve(success(result));
217
- });
218
- _this.once('rejected', function (reason) {
219
- if (error)
220
- reject(error(reason));
221
- });
222
- }
223
- });
224
- };
225
- /*
226
- * Appends a rejection handler callback to the promise, and returns a new promise resolving to the return value of
227
- * the callback if it is called, or to its original fulfillment value if the promise is instead fulfilled.
228
- */
229
- SimplePromise.prototype.catch = function (onRejected) {
230
- return this.then(undefined, onRejected);
231
- };
232
- /*
233
- * Appends a handler to the promise, and returns a new promise which is resolved when the original promise is
234
- * resolved. The handler is called when the promise is settled, whether fulfilled or rejected.
235
- */
236
- SimplePromise.prototype.finally = function (finallyCallback) {
237
- var success = function (result) { return finallyCallback(result); };
238
- var error = function (reason) { return finallyCallback(reason); };
239
- return this.then(success, error);
240
- };
241
- SimplePromise.prototype._resolve = function (result) {
242
- if (this.state !== EPromiseStates.PENDING)
243
- return;
244
- this._state = EPromiseStates.FULFILLED;
245
- this._result = result;
246
- this.dispatch('fulfilled', result);
247
- };
248
- SimplePromise.prototype._reject = function (reason) {
249
- if (this.state !== EPromiseStates.PENDING)
250
- return;
251
- this._state = EPromiseStates.REJECTED;
252
- this._result = reason;
253
- this.dispatch('rejected', reason);
254
- };
255
- return SimplePromise;
256
- }(EventDispatcher_1.EventDispatcher));
257
- exports.SimplePromise = SimplePromise;
258
- //# sourceMappingURL=SimplePromise.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SimplePromise.js","sourceRoot":"","sources":["../src/SimplePromise.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAkD;AAalD,IAAY,cAIX;AAJD,WAAY,cAAc;IACtB,yDAAO,CAAA;IACP,6DAAS,CAAA;IACT,2DAAQ,CAAA;AACZ,CAAC,EAJW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAIzB;AAUD,SAAgB,IAAI,CAAU,MAAU,IAAO,OAAO,MAAW,CAAC,CAAC,CAAC;AAApE,oBAAoE;AAEpE;IAAsC,iCAAe;IAKjD,uBAAY,QAAyD;QAArE,YACI,iBAAO,SAQV;QAZS,aAAO,GAAgB,IAAI,CAAC;QAKlC,KAAI,CAAC,MAAM,GAAG,cAAc,CAAC,OAAO,CAAC;QACrC,KAAI,CAAC,YAAY,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,KAAI,CAAC,CAAC,WAAW,CAAC,CAAC;QAC9D,IAAI;YACA,QAAQ,CAAC,KAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAI,CAAC,EAAE,KAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAI,CAAC,CAAC,CAAC;SAC/D;QAAC,OAAO,CAAC,EAAE;YACR,KAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;SACnB;;IACL,CAAC;IAED,sBAAW,gCAAK;aAAhB;YACI,OAAO,IAAI,CAAC,MAAM,CAAC;QACvB,CAAC;;;OAAA;IAED,sBAAW,iCAAM;aAA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