Skip to content

Commit bf8652a

Browse files
author
pemrouz
committed
feat: dynamically transpile
1 parent 9932be5 commit bf8652a

5 files changed

Lines changed: 297 additions & 37 deletions

File tree

‎client.min.js.gz‎

0 Bytes
Binary file not shown.

‎end.test.js‎

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
const { ripple, page } = await startup()
2323
await page.evaluate(d => { $ = ripple.subscribe('foo').map(d => (console.log("d", d), d)) })
2424
ripple('foo', 'bar')
25-
ripple.emit('loaded', 'foo')
2625
same('bar', await page.evaluate(d => $))
2726
same(1, keys(ripple.server.ws.sockets[0].subscriptions).length)
2827
await page.evaluate(d => Promise.all($.source.emit('stop')))
@@ -245,6 +244,83 @@
245244
page.close()
246245
})
247246

247+
await test('strip server headers', async ({ plan, same }) => {
248+
plan(2)
249+
const { ripple, page } = await startup()
250+
, received = emitterify()
251+
252+
// capture messages
253+
ripple({
254+
name: 'test'
255+
, body: {}
256+
, headers: {
257+
from: d => false
258+
, loaded: 'loaded'
259+
, transpile: 'transpile'
260+
, valid: d => d
261+
}
262+
})
263+
264+
const test = await page.evaluate(async d => {
265+
await ripple.get('test')
266+
return {
267+
headers: Object.keys(ripple.resources.test.headers)
268+
, valid: typeof ripple.resources.test.headers.valid
269+
}
270+
})
271+
272+
same(test.headers, ['valid', 'content-type'], 'headers stripped')
273+
same(test.valid, 'function', 'function headers valid')
274+
275+
page.close()
276+
})
277+
278+
await test('auto dynamically transpile functions', async ({ plan, same }) => {
279+
plan(7)
280+
const { ripple, page } = await startup()
281+
282+
ripple('arrow', d => d)
283+
284+
same(keys(ripple.caches).length, 0, 'empty cache')
285+
286+
const untranspiled = await page.evaluate(async d => ('' + await ripple.get('arrow')))
287+
same(keys(ripple.caches), ['arrow'], 'one cache')
288+
same(ripple.caches.arrow.size, 1, 'one transpilation')
289+
290+
await page.setUserAgent('Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko')
291+
await page.reload()
292+
293+
const transpiled = await page.evaluate(async d => ('' + await ripple.get('arrow')))
294+
same(ripple.caches.arrow.size, 2, 'two transpilations')
295+
same(untranspiled, 'd => d', 'untranspiled')
296+
same(transpiled, 'function (d) { return d; }', 'transpiled')
297+
298+
ripple('arrow', d => false)
299+
300+
same(keys(ripple.caches).length, 0, 'clear transpilation caches on reload')
301+
page.close()
302+
})
303+
304+
await test('opt in dynamically transpile objects with functions + updates', async ({ plan, same }) => {
305+
plan(2)
306+
const { ripple, page } = await startup()
307+
308+
await page.setUserAgent('Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko')
309+
await page.reload()
310+
ripple('arrow', { foo: d => true }, { transpile: { limit: 1 }})
311+
312+
const transpiled1 = await page.evaluate(async d => ('' + (await ripple.get('arrow', 'foo'))))
313+
same(transpiled1, 'function (d) { return true; }', 'transpiled1')
314+
315+
update('foo', d => false)(ripple('arrow'))
316+
await page.reload()
317+
318+
const transpiled2 = await page.evaluate(async d => ('' + (await ripple.get('arrow', 'foo'))))
319+
same(transpiled2, 'function (d) { return false; }', 'transpiled2')
320+
321+
page.close()
322+
})
323+
248324
process.exit(0)
249325

250326
async function startup(){

‎package-lock.json‎

Lines changed: 129 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@
3232
"utilise.emitterify": "^1.3.0"
3333
},
3434
"dependencies": {
35-
"xrs": "*",
35+
"buble": "^0.18.0",
3636
"cryonic": "*",
3737
"express": "^4.14.0",
38+
"lru_map": "^0.3.3",
39+
"platform": "^1.3.4",
3840
"utilise": "*",
39-
"uws": "^8.14.0"
41+
"uws": "^8.14.0",
42+
"xrs": "*"
4043
}
4144
}

0 commit comments

Comments
 (0)