<commit_before>/**
 * @class yootil.sync
 *
 * let my_key = yootil.key("my_key");
 * let sync = new Sync({key: "my_key", data: my_key.get(yootil.user.id())});
 *
 * sync.update(my_key.get()); // Called after setting key
 *
 * @constructor
 */

yootil.sync = class {

	constructor({key = "", data = {}, handler = {}} = {}){
		if(!key){
			return;
		}

		this._trigger_caller = false;
		this._change = (handler && handler.change)? handler.change : this.change;
		this._key = key;
		this._ls_key = key + "_data_sync_" + yootil.user.id();

		// Need to set the storage off the bat

		yootil.storage.set(this._key, data, true, true);

		// Delay adding event (IE issues yet again)

		setTimeout(() => $(window).on("storage", (evt) => {
			if(evt && evt.originalEvent && evt.originalEvent.key == this._key){

				// IE fix

				if(this._trigger_caller){
					this._trigger_caller = false;
					return;
				}

				let event = evt.originalEvent;
				let old_data = event.oldValue;
				let new_data = event.newValue;

				// If old == new, don't do anything

				if(old_data != new_data){
					this._change.bind((handler && handler.change)? handler : this, JSON.parse(new_data), JSON.parse(old_data))();
				}
			}
		}), 100);
	}

	// For outside calls to trigger a manual update

	update(data = {}){
		this._trigger_caller = true;
		yootil.storage.set(this._key, data, true, true);
	}

	change(new_data, old_data){
		let internal_key_data = proboards.plugin.keys.data[this._key];

		if(internal_key_data){
			internal_key_data[yootil.user.id()] = new_data;
		}
	}

	get key(){
		return this._key;
	}

	get local_key(){
		return this._ls_key;
	}

};<commit_msg>Fixed wrong key being used for localStorage<commit_after>/**
 * @class yootil.sync
 *
 * let my_key = yootil.key("my_key");
 * let sync = new Sync({key: "my_key", data: my_key.get(yootil.user.id())});
 *
 * sync.update(my_key.get()); // Called after setting key
 *
 * @constructor
 */

yootil.sync = class {

	constructor({key = "", data = {}, handler = {}} = {}){
		if(!key){
			return;
		}

		this._trigger_caller = false;
		this._change = (handler && handler.change)? handler.change : this.change;
		this._key = key;
		this._ls_key = key + "_data_sync_" + yootil.user.id();

		// Need to set the storage off the bat

		yootil.storage.set(this._ls_key, data, true, true);

		// Delay adding event (IE issues yet again)

		setTimeout(() => $(window).on("storage", (evt) => {
			if(evt && evt.originalEvent && evt.originalEvent.key == this._ls_key){

				// IE fix

				if(this._trigger_caller){
					this._trigger_caller = false;
					return;
				}

				let event = evt.originalEvent;
				let old_data = event.oldValue;
				let new_data = event.newValue;

				// If old == new, don't do anything

				if(old_data != new_data){
					this._change.bind((handler && handler.change)? handler : this, JSON.parse(new_data), JSON.parse(old_data))();
				}
			}
		}), 100);
	}

	// For outside calls to trigger a manual update

	update(data = {}){
		this._trigger_caller = true;
		yootil.storage.set(this._ls_key, data, true, true);
	}

	change(new_data, old_data){
		let internal_key_data = proboards.plugin.keys.data[this._key];

		if(internal_key_data){
			internal_key_data[yootil.user.id()] = new_data;
		}
	}

	get key(){
		return this._key;
	}

	get local_key(){
		return this._ls_key;
	}

};
{'fraction_non_alphanumeric': 0.1657194137002692, 'fraction_numerical': 0.0017947950942267424, 'mean_word_length': 3.2490470139771284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4499085', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1203, 'n_words': 258}