Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
HoloPanio committed Jul 21, 2021
1 parent f167c2c commit 1e208cf
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/src/
/scripts/
/test/
/webpack/
76 changes: 74 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,74 @@
# eventra
A lightweight, but powerful JavaScript event manger that will work in both in the browser and node.js.
<h1 align="center">
Eventra <br>
<a href="https://discord.gg/dTGJ5Bchnq">
<img src="https://img.shields.io/discord/844279877503025182?label=Discord&logo=discord&logoColor=white&style=for-the-badge" />
</a>
<a href="https://www.npmjs.com/package/@duxcore/eventra">
<img src="https://img.shields.io/npm/dw/@duxcore/eventra?logo=npm&style=for-the-badge" />
<img src="https://img.shields.io/npm/v/@duxcore/eventra/latest?label=Latest%20Version&style=for-the-badge" />
</a>
</h1>

Eventra is a lightweight, but powerful JavaScript/TypeScript event manager that comes with built in Type Support and browser/node.js compatibility. Eventra is designed to closely resemble Node.JS Event Emitters so that you can very easily and quickly switch between the two.

# Type Safety
With the ability to use this library with in TypeScript, we have given you the ability to add type definitions directly into the Event Emitter. Once you have added your types, you can very quickly and very easily begin using your type safe events.

### Type Safe Implementation
```ts
// Declare your events interface
interface MyEvents {
'greeting': (message: string) => void;
}

const eventra = new Eventra<MyEvents>();

// Create your event listener
eventra.on('greeting', (msg) => {
console.log("Received a greeting message:", msg);
});

// Emit your new event
eventra.emit('greeting', "Hello User");
```

# JavaScript Implementation
To implement this into your JavaScript application, it is a very similar process to the one listed above. Simply declare your event emitter and start using it.

### Plain JavaScript example
```js
const eventra = new Eventra();

// Create your event listener
eventra.on('greeting', (msg) => {
console.log("Received a greeting message:", msg);
});

// Emit your new event
eventra.emit('greeting', "Hello User");
```

# Browswer Implementation
When we ship this library, we also ship it with a webpacked version so that you may simply slot it into the browser. To do so you can use the `Eventra` namespace and call the class from that. Here is an example as such:

### Browswer Example
```html
<script src='https://cdn.jsdelivr.net/gh/duxcore/eventra@v1.0.0/dist/eventra.min.js'></script>
<script>
const eventra = new Eventra.Eventra();
eventra.on("interval", () => {
console.log("Interval Event Triggered");
});
eventra.once("singular", () => {
console.log("Singular Event Triggered");
});
setInterval(() => {
eventra.emit('interval');
eventra.emit('singular');
}, 1000)
</script>
```
4 changes: 0 additions & 4 deletions dist/eventra.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ class Eventra {
}
}
exports.Eventra = Eventra;
const ev = new Eventra();
ev.on("hello", (msg) => {
console.log("Recieved greeting:", msg);
});


/***/ }),
Expand Down
2 changes: 1 addition & 1 deletion dist/eventra.min.js

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"repository": "https://github.com/duxcore/eventra.git",
"author": "Jackson Roberts <jackson@holopanio.com>",
"license": "GPL-3.0",
"private": false,
"scripts": {
"build": "zx scripts/build.mjs"
"build": "zx scripts/build.mjs",
"deploy": "yarn build -wp; yarn publish;"
},
"devDependencies": {
"@vercel/ncc": "^0.29.0",
Expand Down

0 comments on commit 1e208cf

Please sign in to comment.