Last active
March 24, 2017 11:51
-
-
Save dgieselaar/b740897f42c50c5ccaea to your computer and use it in GitHub Desktop.
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
let ctrl = this, | |
listType = 'following', | |
listItems, | |
state; | |
let fetchData = ( ) => { | |
state = 'pending'; | |
$http({ | |
url: `/api/user/list/${listType}` | |
}) | |
.success( ( response ) => { | |
listItems = response; | |
state = 'resolved'; | |
}) | |
.error( ( response ) => { | |
listItems = null; | |
state = 'rejected'; | |
}); | |
}; | |
ctrl.getListItems = ( ) => listItems; | |
ctrl.isLoading = ( ) => state === 'pending'; | |
ctrl.setListType = ( type ) => { | |
if(listType !== type) { | |
listType = type; | |
fetchData(); | |
} | |
}; |
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
let ctrl = this; | |
listType = 'following', | |
listResource = resource( | |
( ) => `/api/user/list/${listType}`, | |
{ scope: $scope } | |
); | |
ctrl.getListItems = ( ) => listResource.data(); | |
ctrl.isLoading = ( ) => listResource.state() === 'pending'; | |
ctrl.setListType = ( type ) => { | |
listType = type; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment