Skip to content

Instantly share code, notes, and snippets.

@victorhqc
Created December 15, 2017 12:52
Show Gist options
  • Save victorhqc/ec2aea2f6fe9622b9556cb6b27e43ab4 to your computer and use it in GitHub Desktop.
Save victorhqc/ec2aea2f6fe9622b9556cb6b27e43ab4 to your computer and use it in GitHub Desktop.
Angular 1.X Redux-Controller
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', function($scope, TodoService) {
function addTodo($scope, TodoService) {
return function curriedAddTodo(title, description) {
$scope.title = '';
$scope.description = '';
$scope.todos = TodoService.todosReducer(
$scope.todos,
TodoService.addTodo(title, description)
);
};
}
function removeTodo($scope, TodoService) {
return function curriedRemoveTodo(id) {
$scope.todos = TodoService.todosReducer(
$scope.todos,
TodoService.removeTodo(id)
);
};
}
$scope.todos = TodoService.todosReducer([], {});
$scope.addTodo = addTodo($scope, TodoService);
$scope.removeTodo = removeTodo($scope, TodoService)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment