Git Product home page Git Product logo

Comments (1)

siegesmund avatar siegesmund commented on August 25, 2024

Definitely not a stupid question :).

So, you're correct that there isn't a built-in method in AbstractCollection. This is because AbstractCollection is intended as a building block to create collections with any datastore and operations that affect data on both the client and server side have to be written with regard to the datastore that you're using on the client side. For example, with insertion, you'd presumably want to insert your object into your client-side database, call the server-side insert method, then reverse your client-side insertion if the server-side insertion failed (because, for example, you aren't authorized to insert on this collection). That code logic is different depending on whether you use Core Data, Realm, or a plain old array to store your data client-side.

The MeteorCollection class holds documents that are subclasses of MeteorDocument. It stores these documents in an array. It's insert method looks like this:

public func insert(document: T) {

       // save the document to the built-in documents array
        documents[document._id] = document
        collectionSetDidChange() // send a notification that the set has changed

        // now try to insert the document on the server, but remove it if the attempt fails
        client.insert(self.name, document: [document.fields()]) { result, error in

            if error != nil {
                self.documents[document._id] = nil
                self.collectionSetDidChange()
                log.error("\(error!)")
            }

        }

    } 

To see more in-depth examples of how this might work in practice, have a look at either one of the Todos examples, or the MeteorCollection class.

If this is still hazy, let me know.

from swiftddp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.