Skip to content

Commit

Permalink
chore: move to es6 and drop nodejs < 14 support (#53)
Browse files Browse the repository at this point in the history
* chore: move to es6 and drop nodejs < 14 support

* refactor: cleaner code

* style: fix lint

* docs: update readme

* docs: update example

* docs: fix indentation

* fix: move check for subs

* fix: import
  • Loading branch information
robertsLando authored May 17, 2022
1 parent 3a55ef4 commit 53c79c4
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 196 deletions.
53 changes: 19 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,45 +41,30 @@ npm install aedes-cached-persistence --save
In order to reuse aedes-cached-persistence, you need to:

```js
'use strict'

var util = require('util')
var CachedPersistence = require('aedes-cached-persistence')
const CachedPersistence = require('aedes-cached-persistence')

// if you need http://npm.im/aedes-packet, it is available
// from this module as well
// var Packet = CachedPersistence.Packet

function MyPersistence (opts) {
if (!(this instanceof MyPersistence)) {
return new MyPersistence(opts)
}
// initialize your data here

CachedPersistence.call(this, opts)
}

util.inherits(MyPersistence, CachedPersistence)

MyPersistence.prototype.addSubscriptions = function (client, subs, cb) {
// ..persistence specific implementation..

// call this._addedSubscriptions when you are done
this._addedSubscriptions(client, subsObjs, cb)
}

MyPersistence.prototype.removeSubscriptions = function (client, subs, cb) {
// ..persistence specific implementation..

// call this._addedSubscriptions when you are done
this._removedSubscriptions(client, subs.map(subs, client), cb)
// const { Packet } = CachedPersistence

class MyPersistence extends CachedPersistence {
constructor(opts) {
super(opts)
}
addSubscriptions(client, subs, cb) {
// ..persistence specific implementation..
// call super._addedSubscriptions when you are done
super._addedSubscriptions(client, subs.map(mapSub), cb)
}
removeSubscriptions(client, subs, cb) {
// ..persistence specific implementation..
// call super._removedSubscriptions when you are done
super._removedSubscriptions(client, subs.map(mapSub), cb)
}
}

function toSubObj (sub) {
return {
clientId: this.id,
topic: sub.topic
}
function mapSub (sub) {
return { topic: sub.topic }
}
```

Expand Down
Loading

0 comments on commit 53c79c4

Please sign in to comment.