How do I view existing realtime collaboration data model? I call getRoot method:
var collaborative_model = rtpg.realtimeDoc.getModel().getRoot()
When I vew collaborative_model object in debug, I see cryptic properties only. Not sure if or how my model is saved.
Can I do some kind of variable dump of the model?
You can use https://gist.github.com/cowsrule/6348393 as a mostly plug-and-play dumper for the realtime API collaborative objects. As this relies on internals of the realtime API it will need to be updated (read: break) the next time they update the API.
To use, include on your webpage and set window.remoteDoc to be your realtime document.
To call, pass in the ID of the CollaborativeObject you are interested in inspecting.
The root is just a CollaborativeMap, so you can use the standard map methods to explore its values.
The relevant methods there for digging into the model are keys() and values().
A lot of these data model classes have obfuscated methods that are a part of the internal implementation. The best way to see what methods are publicly available is to look at the API reference.
Related
Is there an easy accessible function to get manifest data in javascript to check if the model is done translating?
something like viewerApp.getManifest().progress. Where viewerApp is a ViewingApplication.
Is there something like this, or should I retrieve the data via server code and pass it on to javascript.
No, there is not an client side API as you mentioned to get the progress of model translation.
I am interested in the reason why doing that way. Actually, the ViewingApplication is a client side API and is used to view the model when the model is already translated, it's not suggested to request the translation progress by this API.
If you want to get the status of the translation progress, Yes, using the GET :urn/Manifest to get the progress.
I am starting an Ember application from scratch that will connect to many non-standard JSON APIs which I don't control and from which I only need bits and pieces of data. My first attempt was to use jQuery alone but the code quickly became hard to read and maintain.
I want to use the Ember-Data RESTAdapter with some Serializers. I may need multiple Adapters and Serializers for the different APIs.
I am trying to figure out a good way to break down the work into logical steps.
What process should I follow?
For example:
"Start with what I need" approach:
Model ALL my objects using the FixtureAdapter as the ApplicationAdapter
Implement sample app using the models to ensure it's logically correct
Switch the FixtureAdapter for the RESTAdapter
Extend the RESTAdapter for each Model to map to the different APIs
Create a Serializer for each Model Adapter
-or-
"Start with what I can get" approach:
Extend a SINGLE ModelAdapter at a time, mapping it to the necessary API end-point
Create the Model for my ModelAdapter
Create the Serializer for that ModelAdapter
Implement model in the app
Repeat
I'm new to AngularJS and am trying to build myself a simple little app. I have JSON data for the app being fetched with $resource, and this data should be the same across multiple views/routes. However, when I go to a new route, the JSON data (stored as $scope.data) is no longer available to the new view. What can I do to pass this data to the new view and not require another fetch? (The tutorial phone-catalog app re-fetches this data every time from what I can tell.)
From what I understand, $rootScope can do this but it seems to be generally frowned upon. I apologize if this doesn't make much sense; I'm very much diving in the deep end here.
Use a service to store the data. Inject that service into each controller that needs access to this data. Each time a controller is created and executes (because you switch to another view/route), it can ask the service for the data. If the service doesn't yet have the data, it can make a request to the server and return a promise to the controller (see below for how to do that). If the service has the data, it can return it to the controller immediately.
See also Processing $http response in service
Note that services are singletons, unlike controllers.
Another variation: when the service is created, it can go fetch the data itself, and then store it for later use. Controllers can than $watch properties or functions on the service. For an example of this approach see How do I store a current user context in Angular?
I'm writing an app using Node.js and Express.js. The app has a (small) REST API and then a web front end. I use MongoDb.
For the API, I tend POST data to some endpoint and then do processing or whatever, and dump it in a database. However, I have some database schema I would like to enforce. What are my options / best practices for enforcing a specific structure on my POST data so I know that certain fields are present and of specific types.
It would be nice if this could be done at the middleware level, but it isn't necessary. What do people usually do for validation / schema enforcement?
node-validator is what you are looking for. You can use it as a standalone module like this
var check = require('validator').check;
//Validate
check('test#email.com').len(6, 64).isEmail(); //Methods are chainable
check('abc').isInt(); //Throws 'Invalid integer'
Or you can use express-validator which is built on top of node-validator as a middleware.
Here is a more recent benchmark of various JSON schema validators.
Also, for best practices you may want to check out JSON-schema which attempts to lay out a standard way of defining how a JSON object should be defined.
I was so excited to use GWT Maps API that wrote a service which takes LatLng and LatLngBounds in its interface... Only to find out at runtime that those classes do not implement Serializable, probably because they are Javascript native objects.
What would be the best approach to work with location data types on the server side with GWT then? Are there any libraries which already provide serializable classes and conversion to/from LatLng & company? Or everybody just writes their own wrappers?
See if any of this code I wrote helps you out:
https://github.com/dartmanx/mapmaker/blob/master/src/main/java/org/jason/mapmaker/client/util/GoogleMapUtil.java
GWT provides the ability to create Custom Field Serializers for classes that don't implement Serializable (or IsSerializable). However, JavaScriptObject is an odd duck indeed and doesn't let you directly access any of its data members on the Java side. So, writing a serializer is going to be a challenge at best.
You may also wish to have a look at google's docs about what sorts of values can be returned:
http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI.html#passing-javascript