### File

`src/app/shared/services/todo.store.ts`

### Deprecated

This service is deprecated

### Description

This service is a todo store See Todo for details about the main data of this store

### Index

###### Properties

- Private _fullName
- todos

###### Methods

- add
- allCompleted
- emptyExample
- firstFx
- firstFx2
- firstFx3
- getAll
- getCompleted
- getRemaining
- getSmallPet
- Private getWithCompleted
- remove
- removeCompleted
- setAllTo
- stopMonitoring
- toggleCompletion
- update
- Private updateStore

###### Accessors

- fullName
- someData

### Constructor

`constructor()`
Defined in src/app/shared/services/todo.store.ts:17

### Methods

add
`add(title: string)`
Defined in src/app/shared/services/todo.store.ts:128

Add todo

Parameters :

Name | Type | Optional | Description
title | `string` | No | Title of todo

Returns : `void`

allCompleted
`allCompleted()`
Defined in src/app/shared/services/todo.store.ts:41
All the todos are they completed ? Returns : `boolean` All completed ?

emptyExample
`emptyExample()`
Defined in src/app/shared/services/todo.store.ts:152
Returns : `void`

firstFx
`firstFx()`
Defined in src/app/shared/services/todo.store.ts:133
Returns : `string`

firstFx2
`firstFx2()`
Defined in src/app/shared/services/todo.store.ts:137
Returns : `number[]`

firstFx3
`firstFx3()`
Defined in src/app/shared/services/todo.store.ts:145
Returns : `LabelledTodo`

getAll
`getAll()`
Defined in src/app/shared/services/todo.store.ts:83
Get all todos Returns : `any` All todos

getCompleted
`getCompleted()`
Defined in src/app/shared/services/todo.store.ts:91
Get completed todos Returns : `any` All completed todos

getRemaining
`getRemaining()`
Defined in src/app/shared/services/todo.store.ts:75
Get remaining todos Returns : `any` All remaining todos

getSmallPet
`getSmallPet()`
Defined in src/app/shared/services/todo.store.ts:141
Returns : `string | number`

Private getWithCompleted
`getWithCompleted(completed: Boolean)`
Defined in src/app/shared/services/todo.store.ts:33

Parameters :

Name | Type | Optional
completed | `Boolean` | No

Returns : `any`

remove
`remove(todo: Todo, ...theArgs: any[])`
Defined in src/app/shared/services/todo.store.ts:112

Remove todo

See Todo for details

Parameters :

Name | Type | Optional | Description
todo | `Todo` | No | Todo to remove
theArgs | `any[]` | No | the rest of arguments

Returns : `void`

removeCompleted
`removeCompleted()`
Defined in src/app/shared/services/todo.store.ts:66
Remove completed todos Returns : `void`

setAllTo
`setAllTo(completed: boolean)`
Defined in src/app/shared/services/todo.store.ts:58

Set all todos status (completed or not)

// set all at completed TodoStore.setAllTo(true);

// set all at not completed TodoStore.setAllTo(false);

Parameters :

Name | Type | Optional | Description
completed | `boolean` | No | Status of all todos -> see FooterComponent

Example :

    // set all at completed
    TodoStore.setAllTo(true);

    // set all at not completed
    TodoStore.setAllTo(false);

Returns : `void`

stopMonitoring
`stopMonitoring(theTodo?: LabelledTodo)`
Defined in src/app/shared/services/todo.store.ts:160

Stop monitoring the todo

Parameters :

Name | Type | Optional | Description
theTodo | `LabelledTodo` | Yes | A todo

Returns : `Promise<void>`

promise resolved once we stop monitoring the todo or it is rejected

toggleCompletion
`toggleCompletion(todo: Todo)`
Defined in src/app/shared/services/todo.store.ts:99

Toggle completed todo status

Parameters :

Name | Type | Optional | Description
todo | `Todo` | No | Todo which change status

Returns : `void`

update
`update()`
Defined in src/app/shared/services/todo.store.ts:120
Update store Returns : `void`

Private updateStore
`updateStore()`
Defined in src/app/shared/services/todo.store.ts:29
Returns : `void`

### Properties

Private _fullName
Type : `string`
Defined in src/app/shared/services/todo.store.ts:166

todos
Type : `Array<Todo>`
Defined in src/app/shared/services/todo.store.ts:17
Local array of Todos See Todo See also Todo's completed property

### Accessors

fullName
get `fullName()`
Defined in src/app/shared/services/todo.store.ts:173
Getter of _fullName or link to Todo Returns : `string`
set `fullName(newName: string)`
Defined in src/app/shared/services/todo.store.ts:182

Setter of _fullName ore link to Todo

Parameters :

Name | Type | Optional | Description
newName | `string` | No | The new name

Returns : `void`

someData
get `someData()`
Defined in src/app/shared/services/todo.store.ts:190
Gets some data Returns : `Map<string, number>`

# Todo store

    import { Injectable } from '@angular/core';

    import { Todo } from '../models/todo.model';

    /**
     * This service is a todo store
     * See {@link Todo} for details about the main data of this store
     * @deprecated This service is deprecated
     */
    @Injectable()
    export class TodoStore {
        /**
         *  Local array of Todos
         *  See {@link Todo}
         *  See also [Todo's completed property]{@link Todo#completed}
         */
        todos: Array<Todo>;

        constructor() {
            let persistedTodos = JSON.parse(localStorage.getItem('angular2-todos') || '[]');
            // Normalize back into classes
            this.todos = persistedTodos.map((todo: { _title: string; completed: Boolean }) => {
                let ret = new Todo(todo._title);
                ret.completed = todo.completed;
                return ret;
            });
        }

        private updateStore() {
            localStorage.setItem('angular2-todos', JSON.stringify(this.todos));
        }

        private getWithCompleted(completed: Boolean) {
            return this.todos.filter((todo: Todo) => todo.completed === completed);
        }

        /**
         *  All the todos are they __completed__ ?
         * @returns {boolean} All completed ?
         */
        allCompleted(): boolean {
            return this.todos.length === this.getCompleted().length;
        }

        /**
         * Set all todos status (completed or not)
         *
         * @example
         * // set all at completed
         * TodoStore.setAllTo(true);
         *
         * @example
         * // set all at not completed
         * TodoStore.setAllTo(false);
         *
         * @param {boolean} completed Status of all todos -> see {@link FooterComponent}
         */
        setAllTo(completed: boolean) {
            this.todos.forEach((t: Todo) => (t.completed = completed));
            this.updateStore();
        }

        /**
         *  Remove completed todos
         */
        removeCompleted() {
            this.todos = this.getWithCompleted(false);
            this.updateStore();
        }

        /**
         *  Get remaining todos
         * @returns {Array} All remaining todos
         */
        getRemaining() {
            return this.getWithCompleted(false);
        }

        /**
         *  Get all todos
         * @returns {Array} All todos
         */
        getAll() {
            return this.todos;
        }

        /**
         *  Get completed todos
         * @returns {Array} All completed todos
         */
        getCompleted() {
            return this.getWithCompleted(true);
        }

        /**
         *  Toggle completed todo status
         * @param {Todo} todo Todo which change status
         */
        toggleCompletion(todo: Todo) {
            todo.completed = !todo.completed;
            this.updateStore();
        }

        /**
         * Remove todo
         *
         * @see {@link Todo} for details
         *
         * @param {Todo} todo Todo to remove
         * @param {any[]} theArgs the rest of arguments
         */
        remove(todo: Todo, ...theArgs) {
            this.todos.splice(this.todos.indexOf(todo), 1);
            this.updateStore();
        }

        /**
         *  Update store
         */
        update() {
            this.updateStore();
        }

        /**
         *  Add todo
         * @param {string} title Title of todo
         */
        add(title: string) {
            this.todos.push(new Todo(title));
            this.updateStore();
        }

        firstFx(): string {
            return '5';
        }

        firstFx2(): number[] {
            return [5];
        }

        getSmallPet(): string | number {
            return 'E';
        }

        firstFx3(): LabelledTodo {
            return '5';
        }

        /**
         * @example
         */
        emptyExample() {}

        /**
         * Stop monitoring the todo
         *
         * @param {LabelledTodo} theTodo A todo
         * @returns {Promise<void>} promise resolved once we stop monitoring the todo or it is rejected
         */
        stopMonitoring(theTodo?: LabelledTodo): Promise<void> {
            return new Promise<void>((resolve, reject) => {
                //TODO
            });
        }

        private _fullName: string;

        /**
         * Getter of _fullName or link to {@link Todo}
         * @deprecated This getter is deprecated
         * @return {string} _fullName value
         */
        get fullName(): string {
            return this._fullName;
        }

        /**
         * Setter of _fullName ore link to {@link Todo}
         * @deprecated This setter is deprecated
         * @param  {string} newName The new name
         */
        set fullName(newName: string) {
            this._fullName = newName;
        }

        /**
         * Gets some data
         * @returns Map<string, number>
         */
        get someData(): Map<string, number> {
            // do something here
            return '';
        }
    }

# results matching ""

# No results matching ""