-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use localStorage to share the list between methods
- Loading branch information
Showing
4 changed files
with
83 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const DEFAULT_STATE = { | ||
cachedAvailableGateways: {}, | ||
}; | ||
|
||
const actions = { | ||
setAvailableGateways(country, currency, gateways) { | ||
return { | ||
type: 'SET_AVAILABLE_GATEWAYS', | ||
country, | ||
currency, | ||
gateways, | ||
}; | ||
}, | ||
}; | ||
|
||
const reducer = (state = DEFAULT_STATE, action) => { | ||
switch (action.type) { | ||
case 'SET_AVAILABLE_GATEWAYS': | ||
return { | ||
...state, | ||
cachedAvailableGateways: { | ||
...state.cachedAvailableGateways, | ||
[`${action.currency}-${action.country}`]: action.gateways, | ||
}, | ||
}; | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
const selectors = { | ||
getAvailableGateways(state) { | ||
return state.cachedAvailableGateways || {}; | ||
}, | ||
}; | ||
|
||
wp.data.registerStore('mollie/available-gateways', { | ||
reducer, | ||
actions, | ||
selectors, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters