   
 }
 
+@objc public class Component : ComponentBehaviour {
+  var isEnabled:Bool = true
+  private(set) weak var node:SKNode?
+  private var behaviour:ComponentBehaviour { self as ComponentBehaviour }
+  init() {  }
+  
+  
+  final private func setupSubscribers() {
+    NSNotificationCenter.defaultCenter().removeObserver(self)
+    if self.behaviour.didAddNodeToScene?() != nil {
+      NSNotificationCenter.defaultCenter().addObserver(self, selector: "internalDidAddNodeToScene", name: "internalDidAddNodeToScene", object: self.node?)
+    }
+  }
+  
+  final private func internalDidAddToNode() {
+    self.setupSubscribers()
+    self.behaviour.didAddToNode?()
+  }
+
+  final private func internalDidAddNodeToScene() {
+    self.behaviour.didAddNodeToScene?()
+  }
+  
+  deinit {
+    NSNotificationCenter.defaultCenter().removeObserver(self)
+  }
+  
+}
+
+
+
 
 final private class InternalComponentContainer {
   var components = [String:Component]()

import SpriteKit


@objc protocol Component {
  var isEnabled:Bool { get set }
  weak var node:SKNode? { get set}
  optional func didAddToNode()
  optional func didRemoveFromNode()
  optional func didAddNodeToScene()

  final func removeComponentWithKey(key:String) -> Bool {
    if let componentToRemove = self.componentContainer.components.removeValueForKey(key) {
      componentToRemove.isEnabled = false
      componentToRemove.behaviour.didRemoveFromNode?()
      
      return true
    }
