Comments (8)
Thank you very much for the kind words!
If you're modifying a Mongo Collection, that should absolutely update on the client without a refresh. Restivus wouldn't get in the way of that. All of the Mongo methods are already instrumented to be reactive. So if you modify the collection, whether it be from the client or server, or using DDP or REST, any client that is connected via DDP (which a Meteor client automatically is) will reactively receive any updates as long as the data is published to them, and they are subscribed to it. If you're sure you're doing the Pub-Sub correctly, can you give me the repro steps, or an example repo?
Also, I don't think you're doing this, but just to be clear, you're not trying to create a REST API for your meteor app to consume, correct? Because that would destroy the reactivity, and is not the intended use for Restivus. But if you're just trying to allow some external apps CRUD access to your Mongo collections, then that should be reactive over DDP clients, and Restivus won't (or at least it shouldn't) interfere with that. I have personally used Restivus in this manner and seen data update on the client reactively. It should work without you "re-publishing" anything. That's the beauty of Meteor's Tracker system (with a helping hand from DDP). Here's a good write-up on Tracker by @anthonyreid99 if you ever need a refresher.
from meteor-restivus.
thanks for the quick reply - I created a gist which contains my publish and my restivus code (coffeescript): https://gist.github.com/sschuchlenz/6de0dd7098d6bedc2e8c
And no, my meteor app does not consume but provide the API and I suspect that I'm breaking reactivity somehow by doing the insert stuff in my restivus.coffee file but maybe you could take a look?
from meteor-restivus.
Could you do me a favor and add your subscription to the Entries collection (and your initialization of the collection) to the gist? I just want to make sure I accurately reproduce everything.
One thing that's jumping out to me and surprises me that it's not throwing an error is the fact that you're adding the collection, which sets up all available endpoints on the api/entries
and api/entries/:id
routes for that collection, and then it appears you're attempting to overwrite them (if you created the Entries collection with the name 'entries'
). If you want to overwrite those endpoints, you should do it when adding the collection
Also, the get
endpoint you provided is already automatically provided by Restivus when you called Restivus.addCollection(Entries)
, so you can save yourself those lines of code. None of this will probably solve your problem, but they're just a few things that jump out at me until I can test the code in the gist.
from meteor-restivus.
One thing that I added to the roadmap is getting more example code into the docs, as well as an entire sample project. I think that would help to clarify some of the things I mentioned.
from meteor-restivus.
Ok, I figured out what the problem is, and the good news (I suppose) is that it has nothing to do with Restivus. The publish function is only run when the client initially loads or refreshes a page, and it returns a cursor that has any filters applied. Once the client subscribes, they have access to that published cursor, which is completely reactive. The problem is that in your publication you're filtering out all the documents after the moment that the subscription was activated (which again only happens on a new page load), so any new documents will not be sent to the client. This is because you use a new Date
in your Meteor.publish
function, which will always have the exact time it was created (whatever moment the client subscribed)
Per the suggestion of this Stack Overflow answer, it seems your best bet is probably to just publish the entire collection and do the date filtering client-side. There's also a reactive-publish package that makes the publish function reactive, but I'm not really sure about the implications of something like that. I'd have to think harder than I'm willing to do right now.
So instead of:
Meteor.publish "entries", ->
today = new Date()
Entries.find({available_from: { $lte: today }}, {available_to: { $gte: today }})
you can just publish:
Meteor.publish "entries", ->
Entries.find()
And you'll see the reactivity works properly there (I still get excited when I see REST and Meteor work so well together). I'm going to go ahead and close this issue. If this doesn't resolve it for you I'll be glad to reopen it (or feel free to reopen it yourself).
from meteor-restivus.
that did it - thanks a ton for looking into it and answering in such great detail!
from meteor-restivus.
there is one other thing (which is somewhat related to this issue's thread so I'll post it here):
when I just add
Restivus.addCollection Entries
and drop the code I had for the routes (as you suggested) calling the API results in plain HTML and it seems the default endpoints aren't created.
UPDATE: sorry, please ignore that, the error was my bad - now it works ... :(
from meteor-restivus.
No problem! Glad that solved it for you!
from meteor-restivus.
Related Issues (20)
- Restivus is not a constructor HOT 1
- Restivus.configure is not a function
- HTTP.call inside api issue
- Is it possible to read Content-type: text/plain data HOT 3
- Simple question: Mutual or two way certificate authentication
- First Logging in is not required when using meteor restivus HOT 1
- How to consume a REST api that needs username/password authentication in node.js HOT 1
- onLogInFailure
- Getting 400 Bad Request on Mup Deployed
- Try login with user who does not have password, crashes server
- API should close connection by default HOT 2
- Need corsHeader configurations for CORS
- Role permissions don't work with meteor-roles v3
- Unable to upload multipart file
- Upload multipart file
- Support Meteor 2.3 HOT 1
- Meteor 2.3 not supported HOT 2
- Reason: CORS header ‘Access-Control-Allow-Origin’ missing
- CORS header ‘Access-Control-Allow-Origin’ missing if http status code is not 200
- URL params issue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meteor-restivus.