ForceUniverse / dart-force

Dart Realtime Web Framework!
https://pub.dartlang.org/packages/force
Other
89 stars 9 forks source link

Designing a client DB api. #23

Closed jorishermans closed 9 years ago

jorishermans commented 10 years ago

Let us look at the how a clientside DB api should look like.

cgarciae commented 10 years ago

Id suggest this for the moment, it's a little naive because I know some things will be implemented as Futures, but here is the main idea:

Server

Cargo posts = new Cargo("posts", **conf info**);
Cargo users = new Cargo("users", **conf info**);

posts.publish ((Map request, User|Sender sender) 
{
    if (sender.is (/*some filtering here*/))
        return posts.find(request).filter (/*send a subset of the data*/).
    ...
})

//Maybe also like this

@Publish ('posts')
filterClientPosts (Map request, User|Sender sender)
{
    if (sender.is (/*some filtering here*/))
        return posts.find(request).filter (/*send a subset of the data*/).
    ...
}

Client

ClientCargo posts = new ClientCargo("posts", {topic: "DB API"}); //Send with request
ClientCargo users = new ClientCargo("users"); //All users

posts.onChange (...);
posts.onError(...);

Client stuff should try to register with Angular so that any changes also update the angular templates.

jorishermans commented 10 years ago

That is a great first start. I guess we need to come up with a use case, for example a realtime blog, redit, ... so we can build this example with the new db client api! Probably I need to twist the proposal of you a bit, but it is already a great starting point!

cgarciae commented 10 years ago

Yeah, make the proposal realistic, I am just giving ideas. Meteor's classic examples include: a real time poll, chat, simple social network, Google map with real time gps position of events. I guess the poll is the easiest, you just voted for something in list, each item has a counter, set the getter and setter an angular model to interact with the client-side DB... magic :)

jorishermans commented 10 years ago

I crearted an angular force example application in this github repo. https://github.com/jorishermans/angular-force-example

It is a start ;-)

cgarciae commented 10 years ago

Could you explain to me this peace of code?

 // Construct page
    fs.server.on("/", (req, model) {
       return "angularforce";
    });

It looks like a basic REST request serving a page, and you don't use sender.send. What is going on here?

jorishermans commented 10 years ago

Yes, this is to handle a page, under the hood it is using ForceMVC it return a viewname, in our case "angularforce" page, I prefer users to use this then using starPage: in the constructor ForceServer. But you are right it is to confusing.

I am a beginner with angular.dart so if you can improve my angular code, that would be nice!

cgarciae commented 10 years ago

I also like this API better to serve the start page, but how do you tell when you are using MVC to serve stuff or normal WebSocket messaging?

cgarciae commented 10 years ago

I am also new to angular and Dart in general. I'll run your example as soon as I have the time.

jorishermans commented 10 years ago

forceServer.server.on(... // HTTP Requests => will become forceServer.server.use(... forceServer.on(... // WebSocket messaging

But we need to take this discussion out of this conversation. I added some cargo functionality to the example. So from that point we can look at how we can simplify all of the functionality into a better and simpler api.

cgarciae commented 10 years ago

Can you point me to the cargo part in the example? I just checked but I don't see it.

Is Cargo already running on the client?!?!? If you give me some basic info on how to use it I can start making suggestions.

jorishermans commented 10 years ago

No cargo is for the moment only on the server! I just did a commit! I think we need to work in steps ;-)

cgarciae commented 10 years ago

Ok. I'll check.

jorishermans commented 9 years ago

You can view and look at the implementation of the experimental branch of dart force here.

https://github.com/jorishermans/aproducthuntdart

It is a product hunt example that makes it possible to add and update the records. Would be great if we could get some feedback on this!

jorishermans commented 9 years ago

Version 0.6.0 is been released with the clientside db api, you can look at this video to see more info about clientside DB api https://www.youtube.com/watch?v=MtrZLLzPT74

or look at our examples

https://github.com/ForceExamples/aproducthuntdart

or a simpler version of it

https://github.com/ForceExamples/asimplehuntdart