core-js 0.9.17 → 0.9.18

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.
@@ -0,0 +1,158 @@
1
+ // Based on https://github.com/zenparsing/es-observable/blob/master/src/Observable.js
2
+ var $ = require('./$')
3
+ , $def = require('./$.def')
4
+ , $redef = require('./$.redef')
5
+ , $mix = require('./$.mix')
6
+ , asap = require('./$.task').set
7
+ , assert = require('./$.assert')
8
+ , OBSERVER = require('./$.wks')('observer')
9
+ , isFunction = $.isFunction
10
+ , assertObject = assert.obj
11
+ , assertFunction = assert.fn;
12
+
13
+ // === Abstract Operations ===
14
+ function cancelSubscription(observer){
15
+ var subscription = observer._subscription;
16
+ if(!subscription)return;
17
+ // Drop the reference to the subscription so that we don't unsubscribe
18
+ // more than once
19
+ observer._subscription = undefined;
20
+ try {
21
+ // Call the unsubscribe function
22
+ subscription.unsubscribe();
23
+ } finally {
24
+ // Drop the reference to the inner observer so that no more notifications
25
+ // will be sent
26
+ observer._observer = undefined;
27
+ }
28
+ }
29
+
30
+ function closeSubscription(observer){
31
+ observer._observer = undefined;
32
+ cancelSubscription(observer);
33
+ }
34
+
35
+ function hasUnsubscribe(x){
36
+ return $.isObject(x) && isFunction(x.unsubscribe);
37
+ }
38
+
39
+ function SubscriptionObserver(observer){
40
+ this._observer = observer;
41
+ this._subscription = undefined;
42
+ }
43
+ $mix(SubscriptionObserver.prototype, {
44
+ next: function(value){
45
+ var observer = this._observer
46
+ , result;
47
+ // If the stream if closed, then return a "done" result
48
+ if(!observer)return { value: undefined, done: true };
49
+ try {
50
+ // Send the next value to the sink
51
+ result = observer.next(value);
52
+ } catch (e) {
53
+ // If the observer throws, then close the stream and rethrow the error
54
+ closeSubscription(this);
55
+ throw e;
56
+ }
57
+ // Cleanup if sink is closed
58
+ if(result && result.done)closeSubscription(this);
59
+ return result;
60
+ },
61
+ 'throw': function(value){
62
+ var observer = this._observer;
63
+ // If the stream is closed, throw the error to the caller
64
+ if(!observer)throw value;
65
+ this._observer = undefined;
66
+ try {
67
+ // If the sink does not support "throw", then throw the error to the caller
68
+ if(!('throw' in observer))throw value;
69
+ return observer['throw'](value);
70
+ } finally {
71
+ cancelSubscription(this);
72
+ }
73
+ },
74
+ 'return': function(value){
75
+ var observer = this._observer;
76
+ // If the stream is closed, then return a done result
77
+ if (!observer)return {value: value, done: true};
78
+ this._observer = undefined;
79
+ try {
80
+ // If the sink does not support "return", then return a done result
81
+ if (!('return' in observer))return {value: value, done: true};
82
+ return observer['return'](value);
83
+ } finally {
84
+ cancelSubscription(this);
85
+ }
86
+ }
87
+ });
88
+
89
+ function Observable(subscriber){
90
+ // The stream subscriber must be a function
91
+ this._subscriber = assertFunction(subscriber);
92
+ }
93
+ $mix(Observable.prototype, {
94
+ subscribe: function(observer){
95
+ // The sink must be an object
96
+ assertObject(observer);
97
+ var unsubscribed = false
98
+ , that = this
99
+ , subscription;
100
+ asap.call(global, function(){
101
+ if(!unsubscribed)subscription = that[OBSERVER](observer);
102
+ });
103
+ return {
104
+ unsubscribe: function(){
105
+ if(unsubscribed)return;
106
+ unsubscribed = true;
107
+ if(subscription)subscription.unsubscribe();
108
+ }
109
+ };
110
+ },
111
+ forEach: function(fn, thisArg){
112
+ var that = this;
113
+ return new ($.core.Promise || $.g.Promise)(function(resolve, reject){
114
+ assertFunction(fn);
115
+ that.subscribe({
116
+ next: function(value){ fn.call(thisArg, value); },
117
+ 'throw': function(value){ reject(value); },
118
+ 'return': function(){ resolve(undefined); }
119
+ });
120
+ });
121
+ }
122
+ });
123
+ $redef(Observable.prototype, OBSERVER, function(observer){
124
+ // The sink must be an object
125
+ // Wrap the observer in order to maintain observation invariants
126
+ observer = new SubscriptionObserver(assertObject(observer));
127
+ var subscription;
128
+ try {
129
+ // Call the subscriber function
130
+ subscription = this._subscriber.call(undefined, observer);
131
+ if(!hasUnsubscribe(subscription)){
132
+ var unsubscribe = isFunction(subscription)
133
+ ? subscription
134
+ : function(){ observer['return'](); };
135
+ subscription = {unsubscribe: unsubscribe};
136
+ }
137
+ } catch(e){
138
+ // If an error occurs during startup, then attempt to send the error
139
+ // to the observer
140
+ observer['throw'](e);
141
+ }
142
+ observer._subscription = subscription;
143
+ // If the stream is already finished, then perform cleanup
144
+ if(!observer._observer)cancelSubscription(observer);
145
+ // Return the subscription object
146
+ return subscription;
147
+ });
148
+ $redef(Observable, 'from', function(x){
149
+ if(assertObject(x)._subscriber && x.constructor === this)return x;
150
+ var subscribeFunction = assertFunction(x[OBSERVER]);
151
+ return new this(function(sink){
152
+ subscribeFunction.call(x, sink);
153
+ });
154
+ });
155
+
156
+
157
+ $def($def.G + $def.F, {Observable: Observable});
158
+ $def($def.S, 'Symbol', {observer: OBSERVER});
@@ -1,5 +1,5 @@
1
1
  // https://github.com/benjamingr/RexExp.escape
2
2
  var $def = require('./$.def');
3
3
  $def($def.S, 'RegExp', {
4
- escape: require('./$.replacer')(/[\/\\^$*+?.()|[\]{}]/g, '\\$&', true)
5
- });
4
+ escape: require('./$.replacer')(/[\\^$*+?.()|[\]{}]/g, '\\$&', true)
5
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "core-js",
3
3
  "description": "Standard library",
4
- "version": "0.9.17",
4
+ "version": "0.9.18",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/zloirock/core-js.git"
@@ -26,7 +26,7 @@
26
26
  "karma-opera-launcher": "0.1.x",
27
27
  "karma-phantomjs-launcher": "0.2.x",
28
28
  "promises-aplus-tests": "2.1.x",
29
- "eslint": "^0.22.1"
29
+ "eslint": "0.23.x"
30
30
  },
31
31
  "scripts": {
32
32
  "grunt": "grunt",