Skip to content

Commit

Permalink
Adds strict mode for the commonjs
Browse files Browse the repository at this point in the history
  • Loading branch information
JesuHrz committed Feb 12, 2023
1 parent ed71189 commit d89ad69
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ store.setState(() => {
store.getState() // { counter: 1 }
```

But you can also subscribe a single event
But you can also subscribe to a specific event:

```js
const store = killa({ counter: 0, type: '', filter: '' })
Expand Down Expand Up @@ -124,6 +124,7 @@ store.getState() // { counter: 1, type: '', filter: '' }

```jsx
import killa, { useStore } from 'killa'

const store = killa({ counter: 0, type: '', filter: '' })

const Counter = () => {
Expand All @@ -135,8 +136,8 @@ const Counter = () => {
}
})

const handleCounter = () => {
setState(() => {
const handleCounter = (e) => {
setState((state) => {
return {
...state,
counter: state.counter + 1
Expand Down
7 changes: 6 additions & 1 deletion esbuild.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ const buildForBrowser = async () => {
}

const init = async () => {
buildForCustomEnvironment({ format: 'cjs' })
buildForCustomEnvironment({
format: 'cjs',
banner: {
js: '"use strict"'
}
})
buildForCustomEnvironment({ format: 'esm' })
buildForBrowser()
}
Expand Down
2 changes: 2 additions & 0 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ export const createStore = (initialState = {}, options = {}) => {

return Object.freeze(store)
}

export default createStore
8 changes: 2 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
import { createStore } from './core'
import { useStore } from './react'

export { createStore, useStore }

export default createStore
export { default, createStore } from './core'
export { useStore } from './react'
4 changes: 1 addition & 3 deletions src/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { SYMBOL_STORE } from './utils/constants'

const useSyncExternalStore = useSyncExternalStoreExports.useSyncExternalStoreWithSelector

const _selector = (state) => state

export const useStore = (store, selector = _selector) => {
export const useStore = (store, selector = (state) => state) => {
if (store.STORE !== SYMBOL_STORE) throw new Error('Provide a store valid for killa.')

const state = useSyncExternalStore(
Expand Down

0 comments on commit d89ad69

Please sign in to comment.