Skip to content

Commit

Permalink
Merge pull request #8 from expertlead/hao/nap/dispose
Browse files Browse the repository at this point in the history
Hao/nap/dispose
  • Loading branch information
derrandz authored Mar 24, 2019
2 parents 6fb0cb8 + 6d6699e commit 0d46db5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*v2.0.5*
_Feat: expose nap disposer function as a third arg to the nap function_

*v2.0.4*
_Feat: implement nap for state_

Expand Down
3 changes: 2 additions & 1 deletion examples/todo/state.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ const aggregateAuthenticatedUser = ({ user }) => ({
userFullname: user.username,
})

const userStateNextActionPredicate = (state, onlyTrackedModels) => {
const userStateNextActionPredicate = (state, onlyTrackedModels, dispose) => {
if (state.isAuthenticated) {
console.log("User logged in, send notification to service x")
dispose()
}
}

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"description": "Functional Reactive State Management Library for React, using MobX, implementing the SAM pattern",
"name": "samx",
"version": "2.0.1",
"version": "2.0.5",
"main": "src/index.js",
"repository": "[email protected]:expertlead/samx.git",
"author": [
"Hamza Ouaghad",
"Leonardo Kewitz",
"Invisible Technologies",
"Expertlead"
],
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { configure } from 'mobx'

configure({ enforceActions: 'always', isolatedGlobalState: true })
configure({ enforceActions: 'strict', isolatedGlobalState: true })

export * from 'mobx'

Expand Down
12 changes: 7 additions & 5 deletions src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const State = (transformState, nap = undefined) => ({
let retrieveModels = getModels

if (onlyTrack) {

retrieveModels = () => {
onlyTrack.forEach(
(trackedModel) => {
Expand Down Expand Up @@ -69,13 +69,15 @@ const State = (transformState, nap = undefined) => ({
)

if (nap) {
const nextActionPredicateEffectFn = (stateRepresentation) => (models) => () => {
nap(stateRepresentation, models)
const nextActionPredicateEffectFn = (stateRepresentation) => (models) => (disposer) => () => {
nap(stateRepresentation, models, disposer)
}

reaction(
const dispose = reaction(
retrieveDataFn,
nextActionPredicateEffectFn(stateRepresentation)(retrieveModels())
nextActionPredicateEffectFn(stateRepresentation)(retrieveModels())(
() => dispose()
)
)
}

Expand Down

0 comments on commit 0d46db5

Please sign in to comment.