Skip to content

Commit af0f311

Browse files
author
Chasen Le Hara
committed
1.0.2
1 parent 588f44e commit af0f311

File tree

6 files changed

+566
-0
lines changed

6 files changed

+566
-0
lines changed

dist/.DS_Store

6 KB
Binary file not shown.

dist/amd/can-ndjson-stream.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*can-ndjson-stream@1.0.1#can-ndjson-stream*/
2+
define('can-ndjson-stream', [
3+
'require',
4+
'exports',
5+
'module',
6+
'can-namespace'
7+
], function (require, exports, module) {
8+
'use strict';
9+
var namespace = require('can-namespace');
10+
var ndjsonStream = function (response) {
11+
var is_reader, cancellationRequest = false;
12+
return new ReadableStream({
13+
start: function (controller) {
14+
var reader = response.getReader();
15+
is_reader = reader;
16+
var decoder = new TextDecoder();
17+
var data_buf = '';
18+
reader.read().then(function processResult(result) {
19+
if (result.done) {
20+
if (cancellationRequest) {
21+
return;
22+
}
23+
data_buf = data_buf.trim();
24+
if (data_buf.length !== 0) {
25+
try {
26+
var data_l = JSON.parse(data_buf);
27+
controller.enqueue(data_l);
28+
} catch (e) {
29+
controller.error(e);
30+
return;
31+
}
32+
}
33+
controller.close();
34+
return;
35+
}
36+
var data = decoder.decode(result.value, { stream: true });
37+
data_buf += data;
38+
var lines = data_buf.split('\n');
39+
for (var i = 0; i < lines.length - 1; ++i) {
40+
var l = lines[i].trim();
41+
if (l.length > 0) {
42+
try {
43+
var data_line = JSON.parse(l);
44+
controller.enqueue(data_line);
45+
} catch (e) {
46+
controller.error(e);
47+
cancellationRequest = true;
48+
reader.cancel();
49+
return;
50+
}
51+
}
52+
}
53+
data_buf = lines[lines.length - 1];
54+
return reader.read().then(processResult);
55+
});
56+
},
57+
cancel: function (reason) {
58+
console.log('Cancel registered due to ', reason);
59+
cancellationRequest = true;
60+
is_reader.cancel();
61+
}
62+
});
63+
};
64+
module.exports = namespace.ndjsonStream = ndjsonStream;
65+
});

dist/cjs/can-ndjson-stream.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*can-ndjson-stream@1.0.1#can-ndjson-stream*/
2+
define('can-ndjson-stream', [
3+
'require',
4+
'exports',
5+
'module',
6+
'can-namespace'
7+
], function (require, exports, module) {
8+
'use strict';
9+
var namespace = require('can-namespace');
10+
var ndjsonStream = function (response) {
11+
var is_reader, cancellationRequest = false;
12+
return new ReadableStream({
13+
start: function (controller) {
14+
var reader = response.getReader();
15+
is_reader = reader;
16+
var decoder = new TextDecoder();
17+
var data_buf = '';
18+
reader.read().then(function processResult(result) {
19+
if (result.done) {
20+
if (cancellationRequest) {
21+
return;
22+
}
23+
data_buf = data_buf.trim();
24+
if (data_buf.length !== 0) {
25+
try {
26+
var data_l = JSON.parse(data_buf);
27+
controller.enqueue(data_l);
28+
} catch (e) {
29+
controller.error(e);
30+
return;
31+
}
32+
}
33+
controller.close();
34+
return;
35+
}
36+
var data = decoder.decode(result.value, { stream: true });
37+
data_buf += data;
38+
var lines = data_buf.split('\n');
39+
for (var i = 0; i < lines.length - 1; ++i) {
40+
var l = lines[i].trim();
41+
if (l.length > 0) {
42+
try {
43+
var data_line = JSON.parse(l);
44+
controller.enqueue(data_line);
45+
} catch (e) {
46+
controller.error(e);
47+
cancellationRequest = true;
48+
reader.cancel();
49+
return;
50+
}
51+
}
52+
}
53+
data_buf = lines[lines.length - 1];
54+
return reader.read().then(processResult);
55+
});
56+
},
57+
cancel: function (reason) {
58+
console.log('Cancel registered due to ', reason);
59+
cancellationRequest = true;
60+
is_reader.cancel();
61+
}
62+
});
63+
};
64+
module.exports = namespace.ndjsonStream = ndjsonStream;
65+
});

dist/global/can-ndjson-stream-2.js

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/*[global-shim-start]*/
2+
(function(exports, global, doEval){ // jshint ignore:line
3+
var origDefine = global.define;
4+
5+
var get = function(name){
6+
var parts = name.split("."),
7+
cur = global,
8+
i;
9+
for(i = 0 ; i < parts.length; i++){
10+
if(!cur) {
11+
break;
12+
}
13+
cur = cur[parts[i]];
14+
}
15+
return cur;
16+
};
17+
var set = function(name, val){
18+
var parts = name.split("."),
19+
cur = global,
20+
i, part, next;
21+
for(i = 0; i < parts.length - 1; i++) {
22+
part = parts[i];
23+
next = cur[part];
24+
if(!next) {
25+
next = cur[part] = {};
26+
}
27+
cur = next;
28+
}
29+
part = parts[parts.length - 1];
30+
cur[part] = val;
31+
};
32+
var useDefault = function(mod){
33+
if(!mod || !mod.__esModule) return false;
34+
var esProps = { __esModule: true, "default": true };
35+
for(var p in mod) {
36+
if(!esProps[p]) return false;
37+
}
38+
return true;
39+
};
40+
var modules = (global.define && global.define.modules) ||
41+
(global._define && global._define.modules) || {};
42+
var ourDefine = global.define = function(moduleName, deps, callback){
43+
var module;
44+
if(typeof deps === "function") {
45+
callback = deps;
46+
deps = [];
47+
}
48+
var args = [],
49+
i;
50+
for(i =0; i < deps.length; i++) {
51+
args.push( exports[deps[i]] ? get(exports[deps[i]]) : ( modules[deps[i]] || get(deps[i]) ) );
52+
}
53+
// CJS has no dependencies but 3 callback arguments
54+
if(!deps.length && callback.length) {
55+
module = { exports: {} };
56+
var require = function(name) {
57+
return exports[name] ? get(exports[name]) : modules[name];
58+
};
59+
args.push(require, module.exports, module);
60+
}
61+
// Babel uses the exports and module object.
62+
else if(!args[0] && deps[0] === "exports") {
63+
module = { exports: {} };
64+
args[0] = module.exports;
65+
if(deps[1] === "module") {
66+
args[1] = module;
67+
}
68+
} else if(!args[0] && deps[0] === "module") {
69+
args[0] = { id: moduleName };
70+
}
71+
72+
global.define = origDefine;
73+
var result = callback ? callback.apply(null, args) : undefined;
74+
global.define = ourDefine;
75+
76+
// Favor CJS module.exports over the return value
77+
result = module && module.exports ? module.exports : result;
78+
modules[moduleName] = result;
79+
80+
// Set global exports
81+
var globalExport = exports[moduleName];
82+
if(globalExport && !get(globalExport)) {
83+
if(useDefault(result)) {
84+
result = result["default"];
85+
}
86+
set(globalExport, result);
87+
}
88+
};
89+
global.define.orig = origDefine;
90+
global.define.modules = modules;
91+
global.define.amd = true;
92+
ourDefine("@loader", [], function(){
93+
// shim for @@global-helpers
94+
var noop = function(){};
95+
return {
96+
get: function(){
97+
return { prepareGlobal: noop, retrieveGlobal: noop };
98+
},
99+
global: global,
100+
__exec: function(__load){
101+
doEval(__load.source, global);
102+
}
103+
};
104+
});
105+
}
106+
)({"can-namespace":"can"},window,function(__$source__, __$global__) { // jshint ignore:line
107+
eval("(function() { " + __$source__ + " \n }).call(__$global__);");
108+
}
109+
)
110+
/*can-namespace@1.0.0#can-namespace*/
111+
define('can-namespace', function (require, exports, module) {
112+
module.exports = {};
113+
});
114+
/*can-ndjson-stream@0.1.5#can-ndjson-stream*/
115+
define('can-ndjson-stream', function (require, exports, module) {
116+
var namespace = require('can-namespace');
117+
var ndjsonStream = function (response) {
118+
var is_reader, cancellationRequest = false;
119+
return new ReadableStream({
120+
start: function (controller) {
121+
var reader = response.getReader();
122+
is_reader = reader;
123+
var decoder = new TextDecoder();
124+
var data_buf = '';
125+
reader.read().then(function processResult(result) {
126+
if (result.done) {
127+
if (cancellationRequest) {
128+
return;
129+
}
130+
data_buf = data_buf.trim();
131+
if (data_buf.length !== 0) {
132+
try {
133+
var data_l = JSON.parse(data_buf);
134+
controller.enqueue(data_l);
135+
} catch (e) {
136+
controller.error(e);
137+
return;
138+
}
139+
}
140+
controller.close();
141+
return;
142+
}
143+
var data = decoder.decode(result.value, { stream: true });
144+
data_buf += data;
145+
var lines = data_buf.split('\n');
146+
for (var i = 0; i < lines.length - 1; ++i) {
147+
var l = lines[i].trim();
148+
if (l.length > 0) {
149+
try {
150+
var data_line = JSON.parse(l);
151+
controller.enqueue(data_line);
152+
} catch (e) {
153+
controller.error(e);
154+
cancellationRequest = true;
155+
reader.cancel();
156+
return;
157+
}
158+
}
159+
}
160+
data_buf = lines[lines.length - 1];
161+
return reader.read().then(processResult);
162+
});
163+
},
164+
cancel: function (reason) {
165+
console.log('Cancel registered due to ', reason);
166+
cancellationRequest = true;
167+
is_reader.cancel();
168+
}
169+
});
170+
};
171+
module.exports = namespace.ndjsonStream = ndjsonStream;
172+
});
173+
/*[global-shim-end]*/
174+
(function(){ // jshint ignore:line
175+
window._define = window.define;
176+
window.define = window.define.orig;
177+
}
178+
)();

0 commit comments

Comments
 (0)