# all files / Core/Services/ PersistentStateService.js

100% Statements 16/16
100% Branches 8/8
100% Functions 4/4
100% Lines 16/16

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36

    1

    1

    7

    7

    1
    3
    3

    1
    2
    2
    2

    1
    2
    2
    2

    1
     'use strict';

    // Module:
    var Core = require('../Core');

    var PersistentStateService = function PersistentStateService (
        localStorageService
    ) {
        var PERSISTENT_STATE_KEY = 'PERSISTENT_STATE';

        return {
            get: get,
            set: set,
            remove: remove
        };

        function get (name) {
            var state = localStorageService.get(PERSISTENT_STATE_KEY) || {};
            return state[name] || {};
        }

        function set (name, value) {
            var state = localStorageService.get(PERSISTENT_STATE_KEY) || {};
            state[name] = value;
            localStorageService.set(PERSISTENT_STATE_KEY, state);
        }

        function remove (name) {
            var state = localStorageService.get(PERSISTENT_STATE_KEY) || {};
            delete state[name];
            localStorageService.set(PERSISTENT_STATE_KEY, state);
        }
    };

    Core.service('persistentStateService', PersistentStateService);