<commit_before>const events = require('sdk/system/events');
const {Class} = require('sdk/core/heritage');
const {Ci: {nsICookie2}} = require('chrome');
const {COOKIE: {SESSION_ID, HOST, PATH}} = require('../config');
const {getUnreadCount} = require('../utils/api');
const observer = require('../observer');

const CookieService = Class({
    initialize() {
        this.addListeners();

        // check current auth status
        this.changeAuthStatus();
    },
    addListeners() {
        events.on('cookie-changed', ({subject}) => {
            try {
                const {name, host, path} = subject.QueryInterface(nsICookie2);

                if (name === SESSION_ID && host === HOST && path === PATH) {
                    this.changeAuthStatus();
                }
            }
            catch (err) {
                // silent exception
                return;
            }
        }, true);
    },
    changeAuthStatus() {
        getUnreadCount()
            .then(unreadCount => observer.emitEvent('login', {unreadCount}))
            .catch(() => observer.emitEvent('logout', {user: null}));
    }
});

module.exports = new CookieService();<commit_msg>rewrite cookie service without class<commit_after>const events = require('sdk/system/events');
const {Ci: {nsICookie2}} = require('chrome');
const {COOKIE: {SESSION_ID, HOST, PATH}} = require('../config');
const {getUnreadCount} = require('../utils/api');
const observer = require('../observer');

function changeAuthStatus() {
    getUnreadCount()
        .then(unreadCount => observer.emitEvent('login', {unreadCount}))
        .catch(() => observer.emitEvent('logout', {user: null}));
}

function init() {
    events.on('cookie-changed', ({subject}) => {
        try {
            const {name, host, path} = subject.QueryInterface(nsICookie2);

            if (name === SESSION_ID && host === HOST && path === PATH) {
                changeAuthStatus();
            }
        }
        catch (err) {
            // silent exception
            return;
        }
    }, true);

    // check current auth status
    changeAuthStatus();
}

module.exports = init;
{'fraction_non_alphanumeric': 0.16580796252927402, 'fraction_numerical': 0.001873536299765808, 'mean_word_length': 2.3219284603421464, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '775142', 'n_tokens_mistral': 608, 'n_tokens_neox': 588, 'n_words': 130}