Skip to content

Commit

Permalink
Merge pull request #19 from kwonoj/feat-asmfallback
Browse files Browse the repository at this point in the history
feat(loadmodule): fall back to asm.js if wasm load fails
  • Loading branch information
kwonoj authored Sep 20, 2017
2 parents 4828433 + af981f6 commit be4d90f
Show file tree
Hide file tree
Showing 18 changed files with 2,273 additions and 958 deletions.
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"node_modules": true,
"dist": true
}
}
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
<a name="0.0.6"></a>
## [0.0.6](https://github.com/kwonoj/cld3-asm/compare/v0.0.5...v0.0.6) (2017-09-20)


### Features

* **getloader:** refactor getting loader into closure ([e0155a0](https://github.com/kwonoj/cld3-asm/commit/e0155a0))
* **loadmodule:** fall back to asm.js if wasm load fails ([aef1307](https://github.com/kwonoj/cld3-asm/commit/aef1307))



<a name="0.0.5"></a>
## [0.0.5](https://github.com/kwonoj/cld3-asm/compare/v0.0.4...v0.0.5) (2017-09-18)

Expand Down
41 changes: 41 additions & 0 deletions examples/electron/browserView-preload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { enableLogger, loadModule } from '../../src/index';

enableLogger(console.log.bind(console));

//Initialize cld, then attach into global
const init = async () => {
try {
const cldFactory = await loadModule();
(window as any).cld = cldFactory.create(10, 1000);
} catch (e) {
//tslint:disable-next-line
console.log(`failed to load cld library`, e);
}
};

init();

//demo purpose only: hook loaded page's input event then run cld each time input emits value
const postDOMSetup = () => {
if (!window || !window.location || !window.document || !window.document.body) {
setTimeout(postDOMSetup, 250);
return;
}

document.body.addEventListener('input', (evt: Event) => {
if (!!evt.target && !!(evt.target as any).value) {
const v = (evt.target as any).value;
//we created cld with 10 char as min length of input. Skipping shorter text
if (v.length < 10) {
return;
}
const start = performance.now();
const result = (window as any).cld.findLanguage(v);
const time = performance.now() - start;
//tslint:disable-next-line
console.log(`findLanguage: ${v} took ${time}ms, length ${v.length}`, result);
}
});
};

setTimeout(postDOMSetup, 250);
8 changes: 8 additions & 0 deletions examples/electron/browserView.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>

<body>
<div id="container">
<p>Language detector in BrowserView: Type any languages in textArea and check devTools console output.</p>
</div>
</body>
</html>
15 changes: 15 additions & 0 deletions examples/electron/browserWindow.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html>

<body>
<div id="container">
<p>Language detector in BrowserWindow: Type any languages in textArea</p>
<textarea id="ta" width="400"></textarea>
<p id="out"></p>
</div>

<script>
require('./browserWindow.js');
</script>
</body>

</html>
33 changes: 33 additions & 0 deletions examples/electron/browserWindow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { enableLogger, loadModule } from '../../src/index';

enableLogger(console.log.bind(console));

const init = async () => {
try {
const cldFactory = await loadModule();
const cld = cldFactory.create(10, 1000);

//demo purpose only: hook input event then run cld each time input emits value
(window as any).ta.addEventListener('input', (evt: Event) => {
if (!!evt.target && !!(evt.target as any).value) {
const v = (evt.target as any).value;
//we created cld with 10 char as min length of input. Skipping shorter text
if (v.length < 10) {
return;
}
const start = performance.now();
const result = cld.findLanguage(v);
const time = performance.now() - start;

(window as any).out.innerText = `findLanguage: ${v} \n took ${time}ms, length ${v.length} \n ${JSON.stringify(
result
)}`;
}
});
} catch (e) {
//tslint:disable-next-line
console.log(`failed to load cld library`, e);
}
};

init();
32 changes: 32 additions & 0 deletions examples/electron/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { app, BrowserView, BrowserWindow } from 'electron';

let mainWindow: Electron.BrowserWindow | null = null;

app.on('window-all-closed', () => {
app.quit();
});

app.on('ready', () => {
mainWindow = new BrowserWindow({
width: 1024,
height: 768
});

mainWindow.loadURL(`file://${__dirname}/${process.env.ENTRY}.html`);

if (process.env.ENTRY === 'browserView') {
const view = new BrowserView({
webPreferences: {
nodeIntegration: false,
preload: require.resolve('./browserView-preload')
}
});
mainWindow.setBrowserView(view);
view.setBounds({ x: 0, y: 80, width: 1024, height: 768 });
view.setAutoResize({ width: true, height: true });
view.webContents.loadURL('http://html.com/tags/textarea/#Code_Example');
setTimeout(() => {
view.webContents.openDevTools();
}, 2000);
}
});
Loading

0 comments on commit be4d90f

Please sign in to comment.