memoize-functions
v1.0.0
Published
Create a new object replacing functions with memoized versions
Downloads
5
Maintainers
Readme
memoize-functions
Create a new object replacing functions with memoized versions
Usage
import memoizeFunctions from 'memoize-functions'
let obj = {
info: () =>
({ output: 'I beg your pardon' }),
log: (message = 'Howdy o/') =>
({ output: message }),
warn: ({ message = 'Hey!' }) =>
({ output: message }),
text:
({ output: 'String' }),
}
let newObj = memoizeFunctions(obj)
newObj.log() === newObj.log()
newObj.warn() === newObj.warn()
newObj.info({ message: 'Yo!' }) === newObj.info({ message: 'Yo!' })
newObj.text === newObj.text
Then attributes info
, log
and warn
are replaced by memoized versions
(it supports destructured parameters).
Attribute text
is kept the same, only functions are memoized.
You can also choose which functions should be memoized:
newObj = memoizeFunctions(obj, 'log', 'warn')
newObj.log() === newObj.log()
newObj.warn() === newObj.warn()
newObj.info({ message: 'Yo!' }) !== newObj.info({ message: 'Yo!' })
newObj.text === newObj.text
The attribute log
and warn
are memoized but info
is kept the same.
Contributing
First of all, thank you for wanting to help!
- Fork it.
- Create a feature branch -
git checkout -b more_magic
- Add tests and make your changes
- Check if tests are ok -
npm test
- Commit changes -
git commit -am "Added more magic"
- Push to Github -
git push origin more_magic
- Send a pull request! :heart: :sparkling_heart: :heart: