Skip to content

Commit

Permalink
replace event-emitter package with NodeJS builtin events
Browse files Browse the repository at this point in the history
  • Loading branch information
wommy committed Sep 24, 2024
1 parent f09089c commit d474f80
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 124 deletions.
93 changes: 0 additions & 93 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"@types/localforage": "0.0.34",
"@xmldom/xmldom": "^0.7.5",
"core-js": "^3.18.3",
"event-emitter": "^0.3.5",
"jszip": "^3.7.1",
"localforage": "^1.10.0",
"lodash": "^4.17.21",
Expand Down
7 changes: 4 additions & 3 deletions src/annotations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EventEmitter from "event-emitter";
import { EventEmitter } from "events";
import EpubCFI from "./epubcfi";
import { EVENTS } from "./utils/constants";

Expand Down Expand Up @@ -212,7 +212,7 @@ class Annotations {
* @param {object} styles CSS styles to assign to annotation
* @returns {Annotation} annotation
*/
class Annotation {
class Annotation extends EventEmitter {

constructor ({
type,
Expand All @@ -223,6 +223,7 @@ class Annotation {
className,
styles
}) {
super();
this.type = type;
this.cfiRange = cfiRange;
this.data = data;
Expand Down Expand Up @@ -295,7 +296,7 @@ class Annotation {

}

EventEmitter(Annotation.prototype);
Object.assign(Annotation.prototype, EventEmitter.prototype);


export default Annotations
7 changes: 4 additions & 3 deletions src/book.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EventEmitter from "event-emitter";
import { EventEmitter } from "events";
import {extend, defer} from "./utils/core";
import Url from "./utils/url";
import Path from "./utils/path";
Expand Down Expand Up @@ -47,8 +47,9 @@ const INPUT_TYPE = {
* @example new Book("/path/to/book.epub", {})
* @example new Book({ replacements: "blobUrl" })
*/
class Book {
class Book extends EventEmitter {
constructor(url, options) {
super();
// Allow passing just options to the Book
if (typeof(options) === "undefined" &&
typeof(url) !== "string" &&
Expand Down Expand Up @@ -763,6 +764,6 @@ class Book {
}

//-- Enable binding events to book
EventEmitter(Book.prototype);
Object.assign(Book.prototype, EventEmitter.prototype);

export default Book;
7 changes: 4 additions & 3 deletions src/contents.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EventEmitter from "event-emitter";
import { EventEmitter } from "events";
import {isNumber, prefixed, borders, defaults} from "./utils/core";
import EpubCFI from "./epubcfi";
import Mapping from "./mapping";
Expand All @@ -21,8 +21,9 @@ const TEXT_NODE = 3;
* @param {string} cfiBase Section component of CFIs
* @param {number} sectionIndex Index in Spine of Conntent's Section
*/
class Contents {
class Contents extends EventEmitter {
constructor(doc, content, cfiBase, sectionIndex) {
super();
// Blank Cfi for Parsing
this.epubcfi = new EpubCFI();

Expand Down Expand Up @@ -1259,6 +1260,6 @@ class Contents {
}
}

EventEmitter(Contents.prototype);
Object.assign(Contents.prototype, EventEmitter.prototype);

export default Contents;
7 changes: 4 additions & 3 deletions src/layout.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { extend } from "./utils/core";
import { EVENTS } from "./utils/constants";
import EventEmitter from "event-emitter";
import { EventEmitter } from "events";

/**
* Figures out the CSS values to apply for a layout
Expand All @@ -11,8 +11,9 @@ import EventEmitter from "event-emitter";
* @param {number} [settings.minSpreadWidth=800]
* @param {boolean} [settings.evenSpreads=false]
*/
class Layout {
class Layout extends EventEmitter {
constructor(settings) {
super();
this.settings = settings;
this.name = settings.layout || "reflowable";
this._spread = (settings.spread === "none") ? false : true;
Expand Down Expand Up @@ -255,6 +256,6 @@ class Layout {
}
}

EventEmitter(Layout.prototype);
Object.assign(Layout.prototype, EventEmitter.prototype);

export default Layout;
7 changes: 4 additions & 3 deletions src/locations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import {qs, sprint, locationOf, defer} from "./utils/core";
import Queue from "./utils/queue";
import EpubCFI from "./epubcfi";
import { EVENTS } from "./utils/constants";
import EventEmitter from "event-emitter";
import { EventEmitter } from "events";

/**
* Find Locations for a Book
* @param {Spine} spine
* @param {request} request
* @param {number} [pause=100]
*/
class Locations {
class Locations extends EventEmitter {
constructor(spine, request, pause) {
super();
this.spine = spine;
this.request = request;
this.pause = pause || 100;
Expand Down Expand Up @@ -496,6 +497,6 @@ class Locations {
}
}

EventEmitter(Locations.prototype);
Object.assign(Locations.prototype, EventEmitter.prototype);

export default Locations;
7 changes: 4 additions & 3 deletions src/managers/default/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EventEmitter from "event-emitter";
import { EventEmitter } from "events";
import {extend, defer, windowBounds, isNumber} from "../../utils/core";
import scrollType from "../../utils/scrolltype";
import Mapping from "../../mapping";
Expand All @@ -7,8 +7,9 @@ import Stage from "../helpers/stage";
import Views from "../helpers/views";
import { EVENTS } from "../../utils/constants";

class DefaultViewManager {
class DefaultViewManager extends EventEmitter {
constructor(options) {
super();

this.name = "default";
this.optsSettings = options.settings;
Expand Down Expand Up @@ -1072,6 +1073,6 @@ class DefaultViewManager {
}

//-- Enable binding events to Manager
EventEmitter(DefaultViewManager.prototype);
Object.assign(DefaultViewManager.prototype, EventEmitter.prototype);

export default DefaultViewManager;
7 changes: 4 additions & 3 deletions src/managers/helpers/snap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {extend, defer, requestAnimationFrame, prefixed} from "../../utils/core";
import { EVENTS, DOM_EVENTS } from "../../utils/constants";
import EventEmitter from "event-emitter";
import { EventEmitter } from "events";

// easing equations from https://github.com/danro/easing-js/blob/master/easing.js
const PI_D2 = (Math.PI / 2);
Expand All @@ -22,8 +22,9 @@ const EASING_EQUATIONS = {
}
};

class Snap {
class Snap extends EventEmitter {
constructor(manager, options) {
super();

this.settings = extend({
duration: 80,
Expand Down Expand Up @@ -333,6 +334,6 @@ class Snap {
}
}

EventEmitter(Snap.prototype);
Object.assign(Snap.prototype, EventEmitter.prototype);

export default Snap;
7 changes: 4 additions & 3 deletions src/managers/views/iframe.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import EventEmitter from "event-emitter";
import { EventEmitter } from "events";
import {extend, borders, uuid, isNumber, bounds, defer, createBlobUrl, revokeBlobUrl} from "../../utils/core";
import EpubCFI from "../../epubcfi";
import Contents from "../../contents";
import { EVENTS } from "../../utils/constants";
import { Pane, Highlight, Underline } from "marks-pane";

class IframeView {
class IframeView extends EventEmitter {
constructor(section, options) {
super();
this.settings = extend({
ignoreClass : "",
axis: undefined, //options.layout && options.layout.props.flow === "scrolled" ? "vertical" : "horizontal",
Expand Down Expand Up @@ -846,6 +847,6 @@ class IframeView {
}
}

EventEmitter(IframeView.prototype);
Object.assign(IframeView.prototype, EventEmitter.prototype);

export default IframeView;
7 changes: 4 additions & 3 deletions src/rendition.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EventEmitter from "event-emitter";
import { EventEmitter } from "events";
import { extend, defer, isFloat } from "./utils/core";
import Hook from "./utils/hook";
import EpubCFI from "./epubcfi";
Expand Down Expand Up @@ -40,8 +40,9 @@ import ContinuousViewManager from "./managers/continuous/index";
* @param {boolean} [options.allowScriptedContent=false] enable running scripts in content
* @param {boolean} [options.allowPopups=false] enable opening popup in content
*/
class Rendition {
class Rendition extends EventEmitter {
constructor(book, options) {
super();

this.settings = extend(this.settings || {}, {
width: null,
Expand Down Expand Up @@ -1064,6 +1065,6 @@ class Rendition {
}

//-- Enable binding events to Renderer
EventEmitter(Rendition.prototype);
Object.assign(Rendition.prototype, EventEmitter.prototype);

export default Rendition;
7 changes: 4 additions & 3 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {defer, isXml, parse} from "./utils/core";
import httpRequest from "./utils/request";
import mime from "./utils/mime";
import Path from "./utils/path";
import EventEmitter from "event-emitter";
import { EventEmitter } from "events";
import localforage from "localforage";

/**
Expand All @@ -12,9 +12,10 @@ import localforage from "localforage";
* @param {function} [requester]
* @param {function} [resolver]
*/
class Store {
class Store extends EventEmitter {

constructor(name, requester, resolver) {
super();
this.urlCache = {};

this.storage = undefined;
Expand Down Expand Up @@ -379,6 +380,6 @@ class Store {
}
}

EventEmitter(Store.prototype);
Object.assign(Store.prototype, EventEmitter.prototype);

export default Store;

0 comments on commit d474f80

Please sign in to comment.