Skip to content

Instantly share code, notes, and snippets.

@rt2zz
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rt2zz/0e4b4de955df4f15b64e to your computer and use it in GitHub Desktop.
Save rt2zz/0e4b4de955df4f15b64e to your computer and use it in GitHub Desktop.
// OPTION A - Current Setup
// Logic/Control in Action
Component.componentWillMount = function(){
AccountActions.updateAccount(data)
}
Client.updateAccount = function(data){
apicall(data, function(data){
AccountServerActions.updateAccount(data)
})
}
AccountActions.updateAccount = function(data){
Dispatch(ACCOUNT_UPDATE_APP, data)
Dispatch(ACCOUNT_UPDATE_PENDING, data)
Client.updateAccount()
}
AccountServerActions.updateAccount = function(data){
Dispatch(ACCOUNT_UPDATE_SERVER)
}
// OPTION B - Client Centric
// Logic/Control in Client
Component.componentWillMount = function(){
Client.updateAccount(data)
}
Client.updateAccount = function(data){
AccountActions.updateAccount(data)
apicall(data, function(data){
AccountServerActions.updateAccount(data)
})
}
AccountActions.updateAccount = function(data){
Dispatch(ACCOUNT_UPDATE_APP, data)
Dispatch(ACCOUNT_UPDATE_PENDING, data)
Client.updateAccount()
}
AccountServerActions.updateAccount = function(data){
Dispatch(ACCOUNT_UPDATE_SERVER)
}
// OPTION C - Component Centric
// Logic/Control in Component
Component.componentWillMount = function(){
AccountActions.updateAccount(data)
Client.updateAccount(data)
}
Client.updateAccount = function(data){
apicall(data, function(data){
AccountServerActions.updateAccount(data)
})
}
AccountActions.updateAccount = function(data){
Dispatch(ACCOUNT_UPDATE_APP, data)
Dispatch(ACCOUNT_UPDATE_PENDING, data)
Client.updateAccount()
}
AccountServerActions.updateAccount = function(data){
Dispatch(ACCOUNT_UPDATE_SERVER)
}

API actions can be split up into a couple of cases:

  • Optimistic Update - state is predetermined and server interaction is to mantain consistency
  • Pull Data - state is unknown and we need the server interaction to retrieve or refresh data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment