<commit_before>// Copyright (c) 2013, the polymer_elements.dart project authors.  Please see 
// the AUTHORS file for details. All rights reserved. Use of this source code is 
// governed by a BSD-style license that can be found in the LICENSE file.
// This work is a port of the polymer-elements from the Polymer project, 
// http://www.polymer-project.org/. 

library polymer.elements.polymer_localstorage;

import 'dart:html';
import 'dart:async';
import 'dart:convert';
import 'package:logging/logging.dart';
import 'package:polymer/polymer.dart';

@CustomTag('polymer-localstorage')
class PolymerLocalstorage extends PolymerElement {
  
  /**
   * The key to the data stored in localStorage.
   */
  @published String name;
  
  /**
   * The data associated with the specified name.
   */
  @published var value;

  /**
   * If true, the value is stored and retrieved without JSON processing.
   */
  @observable bool useRaw = false;

  /**
   * If true, auto save is disabled.
   */
  @observable bool autoSaveDisabled = false;
  
  bool loaded = false;
  
  PolymerLocalstorage.created() : super.created();
  
  final _logger = new Logger('polymer-localstorage');

  @override
  void enteredView() {
    super.enteredView();
    print('polymer-localstorage inserted');
    
    // let the bindings complete, so run this async
    // TODO: should we use runAsync here?
    scheduleMicrotask(load);
  }

  valueChanged(oldValue) {
    if (loaded && !this.autoSaveDisabled) {
      this.save();
    }
  }
  
  void load() {
    var s = window.localStorage[name];
    if (s != null && !useRaw) {
      try {
        value = JSON.decode(s);
      } catch (x) {
        value = s;
      }
    } else {
      value = s;
    }
    loaded = true;
    //this.asyncFire('polymer-localstorage-load');
  }

  
  void save() {
    window.localStorage[name] = useRaw ? value : JSON.encode(this.value);
  }
  
}<commit_msg>just added a TODO to the comment<commit_after>// Copyright (c) 2013, the polymer_elements.dart project authors.  Please see 
// the AUTHORS file for details. All rights reserved. Use of this source code is 
// governed by a BSD-style license that can be found in the LICENSE file.
// This work is a port of the polymer-elements from the Polymer project, 
// http://www.polymer-project.org/. 

library polymer.elements.polymer_localstorage;

import 'dart:html';
import 'dart:async';
import 'dart:convert';
import 'package:logging/logging.dart';
import 'package:polymer/polymer.dart';

@CustomTag('polymer-localstorage')
class PolymerLocalstorage extends PolymerElement {
  
  /**
   * The key to the data stored in localStorage.
   */
  @published String name;
  
  /**
   * The data associated with the specified name.
   */
  @published var value;

  /**
   * If true, the value is stored and retrieved without JSON processing.
   */
  @observable bool useRaw = false;

  /**
   * If true, auto save is disabled.
   */
  @observable bool autoSaveDisabled = false;
  
  bool loaded = false;
  
  PolymerLocalstorage.created() : super.created();
  
  final _logger = new Logger('polymer-localstorage');

  @override
  void enteredView() {
    super.enteredView();
    print('polymer-localstorage inserted');
    
    // let the bindings complete, so run this async
    // TODO: should we use runAsync here?
    scheduleMicrotask(load);
  }

  valueChanged(oldValue) {
    if (loaded && !this.autoSaveDisabled) {
      this.save();
    }
  }
  
  void load() {
    var s = window.localStorage[name];
    if (s != null && !useRaw) {
      try {
        value = JSON.decode(s);
      } catch (x) {
        value = s;
      }
    } else {
      value = s;
    }
    loaded = true;
    // TODO this.asyncFire('polymer-localstorage-load');
  }

  
  void save() {
    window.localStorage[name] = useRaw ? value : JSON.encode(this.value);
  }
  
}
{'fraction_non_alphanumeric': 0.11783026213340254, 'fraction_numerical': 0.002076304178562159, 'mean_word_length': 2.812067260138477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1455101', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1156, 'n_words': 359}