Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Storage #47

Open
royhsu opened this issue Sep 19, 2018 · 1 comment
Open

[Feature] Storage #47

royhsu opened this issue Sep 19, 2018 · 1 comment

Comments

@royhsu
Copy link
Owner

royhsu commented Sep 19, 2018

protocol Storage: Collection {

    var changes:  Observable<Changes> { get }

    var isLoaded: Bool { get }

    subscript(key: Key) -> Value?

    func load()

}

protocol AsyncStorage: Storage {

    func value(
        forKey key: Key,
        completion: (Result<Value>) -> Void
    )

}

protocol MutableStorage: Storage {

    func merge(_ other: Sequence)

}

concrete SyncStorage: MutableStorage {

    func addChild(_ storage: Storage) { 
     
        storage.changes.observe { child in

            self.merge(child)

        } 

    }

    subscript(key: Key) -> Value? {

        for child in childStorages {

            if let value = child[key] { return value }
         
        }

        asynchronouslyGettingValueFromChildStoragesIfNeeded()

    }
    
}
@royhsu
Copy link
Owner Author

royhsu commented Sep 20, 2018

The updating strategy is like how CoreData does.

  1. Parent observes changes from children.
  2. Merge changes if that happens.
  3. Forwarding all merged changes to outside.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant