@eroc/core
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -1,2 +0,2 @@ | ||
/* @eroc/core v3.0.0 2020-04-22T12:41:02.315Z licensed MIT */ | ||
/* @eroc/core v3.0.1 2020-05-09T00:13:19.459Z licensed MIT */ | ||
const startEventRecorder = (core) => { | ||
@@ -18,6 +18,3 @@ const events = []; | ||
} | ||
const { | ||
events, | ||
listener, | ||
} = eventRecorder; | ||
const { listener } = eventRecorder; | ||
core.off(ALL, listener); | ||
@@ -24,0 +21,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
/* @eroc/core v3.0.0 2020-04-22T12:41:02.315Z licensed MIT */ | ||
/* @eroc/core v3.0.1 2020-05-09T00:13:19.459Z licensed MIT */ | ||
var Core = (function (exports) { | ||
@@ -21,6 +21,3 @@ 'use strict'; | ||
} | ||
const { | ||
events, | ||
listener, | ||
} = eventRecorder; | ||
const { listener } = eventRecorder; | ||
core.off(ALL, listener); | ||
@@ -27,0 +24,0 @@ }; |
{ | ||
"name": "@eroc/core", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Lightweight framework for scalable applications", | ||
@@ -24,3 +24,3 @@ "license": "MIT", | ||
"jasmine": "^3.5.0", | ||
"rollup": "^2.7.1", | ||
"rollup": "^2.8.2", | ||
"serve": "^11.3.0" | ||
@@ -41,3 +41,3 @@ }, | ||
"env": { | ||
"es6": true, | ||
"es2020": true, | ||
"browser": true, | ||
@@ -67,4 +67,7 @@ "jasmine": true, | ||
"lightweight", | ||
"scalable" | ||
"scalable", | ||
"modules", | ||
"architecture", | ||
"structure" | ||
] | ||
} |
128
README.md
@@ -23,3 +23,3 @@ # core [![Build Status](https://travis-ci.org/mauriciosoares/core.js.svg?branch=master)](https://travis-ci.org/mauriciosoares/core.js) [![Coverage Status](https://img.shields.io/coveralls/mauriciosoares/core.js.svg)](https://coveralls.io/r/mauriciosoares/core.js) [![Code Climate](https://codeclimate.com/github/mauriciosoares/core.js/badges/gpa.svg)](https://codeclimate.com/github/mauriciosoares/core.js) | ||
Everything inside a red square is a module, they work in a way that they don't depend on any other modules, and they should be programmed that way as well. | ||
Everything inside a red square is a module, they work independently. | ||
@@ -37,13 +37,12 @@ | ||
`import { Core, ALL, ERROR } from "./node_modules/@eroc/core/dist/core.js";` | ||
`import { Core, ALL, ERROR } from "./node_modules/@eroc/core/dist/core.es.js";` | ||
With rollup, webpack or parcel | ||
With node, rollup, webpack or parcel | ||
`import { Core, ALL, ERROR } from "@eroc/core";` | ||
NodeJs or Browserify | ||
With old NodeJs or Browserify | ||
`const { Core, ALL, ERROR } = require("@eroc/core");` | ||
`const { Core, ALL, ERROR } = require("@eroc/core/dist/core.umd.cjs");` | ||
Let's start with the tweet module. | ||
@@ -93,3 +92,3 @@ ### Building modules | ||
You might want to stop a module in some point, this can be easily done using the method `core.stop()`. | ||
To stop a module use the method `core.stop()`. | ||
@@ -107,7 +106,11 @@ ```js | ||
First of all, our `tweet` module should notify other modules that something has happened. | ||
Our `tweet` module should notify other modules that something has happened. | ||
#### tweet.js | ||
```js | ||
export { start }; | ||
import { NEW_TWEET } from "./eventNames.js"; | ||
const start = function(emitter) { | ||
@@ -117,4 +120,4 @@ // For the sake of simplicity, use an interval | ||
emitter.emit(NEW_TWEET, { | ||
author: 'Mauricio Soares', | ||
text: 'core is pretty #cool' | ||
author: `Mauricio Soares`, | ||
text: `core is pretty #cool` | ||
}); | ||
@@ -129,5 +132,9 @@ }, 5 * 1000) | ||
#### tweet-list.js | ||
```js | ||
export { start }; | ||
import { NEW_TWEET } from "./eventNames.js"; | ||
const start = function (emitter) { | ||
@@ -140,11 +147,17 @@ emitter.on(NEW_TWEET, (data) => { | ||
Cool right? If one of those modules stop working, than it won't break the other one! | ||
Cool right? If one of those modules stop working, then it will not break the other one! | ||
## Docs | ||
## API | ||
#### core.start(module, options) | ||
### Core | ||
* `module` The module as a name-space (import * as exampleModule from "./exampleModule.js") | ||
#### `new Core()` | ||
Returns a new instance of core. | ||
#### `core.start(module, options)` | ||
* `module` The module as a name-space ( `import * as exampleModule from "./exampleModule.js"` ) | ||
* `options` optional object | ||
@@ -157,7 +170,7 @@ * name optional, String or Symbol that become *moduleInstanceId* | ||
```js | ||
const exampleInstanceId = await Core.start(exampleModule); | ||
const exampleInstanceId = await core.start(exampleModule); | ||
``` | ||
#### core.stop(moduleInstanceId) | ||
#### `core.stop(moduleInstanceId)` | ||
@@ -168,3 +181,3 @@ ```js | ||
#### ALL | ||
#### `ALL` | ||
@@ -181,3 +194,3 @@ Constant to listen to all events | ||
#### ERROR | ||
#### `ERROR` | ||
@@ -194,10 +207,62 @@ Constant to listen to most errors | ||
## tl;dr | ||
### logging | ||
* Check out [this video](https://www.youtube.com/watch?v=s9tdZSa74jo) - Introduction (portuguese) (Old API) | ||
Optional logging to get started | ||
#### `useDefaultLogging(core, logger=console)` | ||
```js | ||
import { Core, useDefaultLogging } from "@eroc/core"; | ||
const core = new Core(); | ||
// listen for all events | ||
useDefaultLogging(core); | ||
``` | ||
### eventRecorder | ||
Utility to record all events. [example](./examples/replay/main.js) | ||
#### `startEventRecorder(core)` | ||
returns an eventRecording. Access `eventRecording.events` to view all past events. | ||
#### `stopEventRecorder(core, eventRecording);` | ||
stops an eventRecording. | ||
```js | ||
import { Core, useDefaultLogging } from "@eroc/core"; | ||
const core = new Core(); | ||
let eventRecording = startEventRecorder(core); | ||
stopEventRecorder(core, eventRecording); | ||
``` | ||
### eventPlayer | ||
Helper to replay events. | ||
#### `replayEvents(core, previousEvents, { sameSpeed = false })` | ||
Will replay previousEvents on core. previousEvents could come from `eventRecording.events` or from a database. Make sure to initialize modules before for it to have any effect. While events are replayed regulare event emits are disabled. This avoids duplicated events in case you emit events as a consequence of another event. | ||
```js | ||
import { Core, replayEvents } from "@eroc/core"; | ||
const core = new Core(); | ||
// ... initialize modules | ||
const events = // get events | ||
replayEvents(core, events, { sameSpeed: true }); | ||
``` | ||
## Maintainers | ||
- Mauricio Soares - https://github.com/mauriciosoares | ||
- GrosSacASac | ||
- GrosSacASac | ||
@@ -261,21 +326,2 @@ ## Contributing | ||
(The MIT License) | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
[MIT License](./LICENSE) |
@@ -21,7 +21,4 @@ export { startEventRecorder, stopEventRecorder }; | ||
} | ||
const { | ||
events, | ||
listener, | ||
} = eventRecorder; | ||
const { listener } = eventRecorder; | ||
core.off(ALL, listener); | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43976
316
1017