CosmicMind / Graph

Graph is a semantic database that is used to create data-driven applications.
http://cosmicmind.com
MIT License
873 stars 72 forks source link

Watch Entity #124

Closed lazarte closed 7 years ago

lazarte commented 7 years ago

Trying to implement a watch for the Entity. Tried to insert and delete entity but the watch delegate doesn't trigger. Please see below code.

func prepareGraph() {
    let graph = Graph()
    let watch = Watch<Entity>(graph: graph).for(types: "Person")
    watch.delegate = self
    let u1 = Entity(type: "Person")
    u1["name"] = "Dan"
    graph.async()
}

Can someone give me an example on how to achieve the watch for the specific entity.

daniel-jonathan commented 7 years ago

Hey, take a look at this sample Watch API project.

Notice how you need to set the WatchEntityDelegate

class ViewController: UIViewController {
    fileprivate var graph: Graph!
    fileprivate var watch: Watch<Entity>!

    open override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white

        prepareGraph()
        prepareWatch()
    }
}

extension ViewController {
    fileprivate func prepareGraph() {
        graph = Graph()
    }

    fileprivate func prepareWatch() {
        watch = Watch<Entity>(graph: graph).for(types: "User").has(tags: "new").member(of: "admin").where(properties: "age")
        watch.delegate = self
    }
}

extension ViewController: WatchEntityDelegate {
    @objc
    func watch(graph: Graph, inserted entity: Entity, source: GraphSource) {

    }
}

If you have any further question for this issue, please reopen the issue. Thank you!