From 752038921efee4241e8aec3d386b35e3ab2a410f Mon Sep 17 00:00:00 2001 From: Guillermo Date: Fri, 14 Oct 2016 00:43:19 -0400 Subject: [PATCH] add node version note --- README.md | 2 + dist/tesseract.js | 258 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 180 insertions(+), 80 deletions(-) diff --git a/README.md b/README.md index 10bf6e4..c5c418a 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ First: ```shell > npm install tesseract.js --save ``` +> Note: Tesseract.js currently requires node v6.8.0 or greater. + Then ```javascript diff --git a/dist/tesseract.js b/dist/tesseract.js index 0784bd1..4ebf16d 100644 --- a/dist/tesseract.js +++ b/dist/tesseract.js @@ -1,4 +1,89 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Tesseract = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o { + var ret = fn(data); + if(ret && typeof ret.then == 'function'){ + console.warn('TesseractJob instances do not chain like ES6 Promises. To convert it into a real promise, use Promise.resolve.') + } + }) + this._resolve = data; + this._instance._dequeue() + runFinallyCbs = true; + }else if(packet.status === 'reject'){ + if(this._reject.length === 0) console.error(data); + this._reject.forEach(fn => fn(data)) + this._reject = data; + this._instance._dequeue() + runFinallyCbs = true; + }else if(packet.status === 'progress'){ + this._progress.forEach(fn => fn(data)) + }else{ + console.warn('Message type unknown', packet.status) + } + + if (runFinallyCbs) { + this._finally.forEach(fn => fn(data)); + } + } +} +},{"../node/index.js":2}],5:[function(require,module,exports){ +const adapter = require('./node/index.js') +const circularize = require('./common/circularize.js') +const TesseractJob = require('./common/job'); +const objectAssign = require('object-assign'); + +function create(workerOptions){ + workerOptions = workerOptions || {}; + var worker = new TesseractWorker(objectAssign({}, adapter.defaultOptions, workerOptions)) + worker.create = create; + return worker; } class TesseractWorker { @@ -213,79 +382,8 @@ class TesseractWorker { } } -var jobCounter = 0; - -class TesseractJob { - constructor(instance){ - this.id = 'Job-' + (++jobCounter) + '-' + Math.random().toString(16).slice(3, 8) - - this._instance = instance; - this._resolve = [] - this._reject = [] - this._progress = [] - } - - then(resolve, reject){ - if(this._resolve.push){ - this._resolve.push(resolve) - }else{ - resolve(this._resolve) - } - - if(reject) this.catch(reject); - return this; - } - catch(reject){ - if(this._reject.push){ - this._reject.push(reject) - }else{ - reject(this._reject) - } - return this; - } - progress(fn){ - this._progress.push(fn) - return this; - } - _send(action, payload){ - adapter.sendPacket(this._instance, { - jobId: this.id, - action: action, - payload: payload - }) - } - - _handle(packet){ - var data = packet.data; - if(packet.status === 'resolve'){ - if(this._resolve.length === 0) console.debug(data); - this._resolve.forEach(fn => { - var ret = fn(data); - if(ret && typeof ret.then == 'function'){ - console.warn('TesseractJob instances do not chain like ES6 Promises. To convert it into a real promise, use Promise.resolve.') - } - }) - this._resolve = data; - this._instance._dequeue() - }else if(packet.status === 'reject'){ - if(this._reject.length === 0) console.error(data); - this._reject.forEach(fn => fn(data)) - this._reject = data; - this._instance._dequeue() - }else if(packet.status === 'progress'){ - this._progress.forEach(fn => fn(data)) - }else{ - console.warn('Message type unknown', packet.status) - } - } -} - - -var DefaultTesseract = createWorker(adapter.defaultOptions) -DefaultTesseract.createWorker = createWorker; +var DefaultTesseract = create() module.exports = DefaultTesseract - - -},{"./common/circularize.js":2,"./node/index.js":1}]},{},[3])(3) +},{"./common/circularize.js":3,"./common/job":4,"./node/index.js":2,"object-assign":1}]},{},[5])(5) }); \ No newline at end of file