// (function(name, factory) { // our basic IO module system that stores every module on modules with the "file" namespace // please use something like browserify rather than rolling your own like this window.modules = window.modules || {}; window.require = window.require || function require(name) { return window.modules[name] || window[name]; }; var exports = {}; factory(exports, window.require); window.modules[name] = exports; }('TodoService', function(exports, require) { var ng = require('ng'); var Inject = ng.Inject; var bind = ng.bind; // We can also make a TodoStore var _todoState = { todos: [ { value:'finish example', created_at: new Date() }, { value:'add tests', created_at: new Date() } ] }; // Our Todo Service var TodoService = exports['TodoService'] = ng. Class({ constructor: [new Inject('todoState'), function(state) { this.state = state; }], get: function(type) { return (type) ? this.state[type] : this.state; }, add: function(todo) { this.state.todos.push({ value: todo, created_at: new Date() }); }, remove: function(index) { this.state.todos.splice(index, 1); } }); // TodoService // Dependency injection var todoInjectables = exports['todoInjectables'] = [ bind('initialTodoState').toValue(_todoState), bind(TodoService).toClass(TodoService), // We only have this to mimic Angular 1's di that is limited only to string tokens. Otherwise we would use `TodoService` class as the token bind('TodoService').toAlias(TodoService) ]; }));