Component.hx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package hide.comp;
  2. class Component {
  3. var ide : hide.Ide;
  4. public var componentName(get, never) : String;
  5. public var element(default,null) : Element;
  6. public var saveDisplayKey : String;
  7. function new(parent:Element,el:Element) {
  8. ide = hide.Ide.inst;
  9. if( el == null )
  10. el = new Element('<div>');
  11. this.element = el;
  12. if( parent != null )
  13. parent.append(element);
  14. }
  15. public function remove() {
  16. element.remove();
  17. }
  18. @:final function get_componentName() return Type.getClassName(Type.getClass(this));
  19. function getDisplayState( key : String ) : Dynamic {
  20. if( saveDisplayKey == null )
  21. return null;
  22. var v = js.Browser.window.localStorage.getItem(saveDisplayKey + "/" + key);
  23. if( v == null )
  24. return null;
  25. return haxe.Json.parse(v);
  26. }
  27. function saveDisplayState( key : String, value : Dynamic ) {
  28. if( saveDisplayKey == null )
  29. return;
  30. js.Browser.window.localStorage.setItem(saveDisplayKey + "/" + key, haxe.Json.stringify(value));
  31. }
  32. function removeDisplayState( key : String ) {
  33. if( saveDisplayKey == null )
  34. return;
  35. js.Browser.window.localStorage.removeItem(saveDisplayKey + "/" + key);
  36. }
  37. }