 import Foundation
 
 public extension DocumentMetadata{
+
+    public var document:BartlebyDocument? { return Bartleby.sharedInstance.getDocumentByUID(self.persistentUID) }
 
     public var debugTriggersHistory:Bool{ return true } // Should be set to False
 

    public func saveStateOf<T:Codable>(_ value:T,identified byKey:String){
        if let value = try? JSON.encoder.encode(value){
            self.statesDictionary[byKey] = value
        }
    }


    public func saveStateString(_ string:String,identified byKey:String){
        if let data = Data(base64Encoded: string){
            self.statesDictionary[byKey] = data
            self.document?.hasChanged()
        }
    }

