Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add store.use() method #58

Merged
merged 1 commit into from
Jul 24, 2016
Merged

add store.use() method #58

merged 1 commit into from
Jul 24, 2016

Conversation

yoshuawuyts
Copy link
Owner

Allows declaring multiple hooks through store.use(hooks). All hooks will now be executed on every call. Useful to register multiple handlers and stuff ✌️

const barracks = require('barracks')
const log = require('choo-log')

const store = barracks()
store.use(log())

const createSend = store.start()

@yoshuawuyts
Copy link
Owner Author

Oh, to clarify: no breaking changes. Minor version

// push an object of hooks onto an array
// obj -> null
function useHooks (hooks) {
assert.equal(typeof hooks, 'object', 'barracks.use: hooks should be an object')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeof [] === 'object'

If we're looking for an object literal the only way to be positive it's that is to do the unwieldy:

Object.prototype.toString.call(hooks) === '[object Object]'

Hurry for a prototypical inheritance system?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, you're obv right... Except that it's valid to append properties onto an array and so it would parse as expected 😂. Not that we should encourage that but, JS is def a weird language. #keepjavascriptweird

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a fun language!

@coveralls
Copy link

coveralls commented Jul 21, 2016

Coverage Status

Coverage increased (+0.5%) to 95.172% when pulling 6bc9b11 on use into b381a97 on master.

@toddself
Copy link
Collaborator

This is cool with me if we don't mind the arrays part? (We could always Array.isArray is if we really wanted to prevent it)

@yoshuawuyts
Copy link
Owner Author

@toddself yeah, I'm not too fussed about it - feel like the assert() calls we got is to prevent people from making lil accidental mistakes - nothing too strict - most common use case I can imagine that would occur is that they'd forget to initialize a function, so it doesn't return an object and we'd catch that and warn ✨

@yoshuawuyts yoshuawuyts changed the title use: add new method add store.use() method Jul 21, 2016
@coveralls
Copy link

coveralls commented Jul 21, 2016

Coverage Status

Coverage increased (+0.5%) to 95.238% when pulling e20ff72 on use into b381a97 on master.

@yoshuawuyts yoshuawuyts mentioned this pull request Jul 22, 2016
3 tasks
@yoshuawuyts
Copy link
Owner Author

Welp, think this is good to merge then ✨

@yoshuawuyts yoshuawuyts merged commit 192afbd into master Jul 24, 2016
@yoshuawuyts yoshuawuyts deleted the use branch July 24, 2016 20:33
@yoshuawuyts
Copy link
Owner Author

released as v8.1.0 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants