Skip to content

Commit

Permalink
feat(emitter): add events emmiter to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Aug 29, 2019
1 parent f5046fe commit 6f01886
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { _config } from '@ecomplus/utils'
import emitter from './lib/emitter'

import addItem from './methods/add-item'
import addPoduct from './methods/add-product'
Expand Down Expand Up @@ -34,7 +35,7 @@ import clear from './methods/clear'
const _key = 'ecomShoppingCart'
const _storage = typeof window === 'object' && window.localStorage

export default function (storeId, storageKey = _key, localStorage = _storage) {
const EcomCart = function (storeId, storageKey = _key, localStorage = _storage) {
const self = this

/**
Expand Down Expand Up @@ -95,6 +96,15 @@ export default function (storeId, storageKey = _key, localStorage = _storage) {
}
}

// events emitter
;['on', 'off', 'once'].forEach(method => {
EcomCart[method] = (ev, fn) => {
emitter[method](ev, fn)
}
})

export default EcomCart

/**
* Construct a new shopping cart instance object.
* @class EcomCart
Expand Down
3 changes: 3 additions & 0 deletions src/lib/emitter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import EventEmitter from 'eventemitter3'
const emitter = new EventEmitter()
export default emitter

0 comments on commit 6f01886

Please sign in to comment.