HERE-API using eval and New Function - here-api

Is there any way to use the Here API without eval and new Function statements?
(since this kind of statements can be blocked on some environments)

I believe this question is specific to the HERE JavaScript API. For example, from mapsjs-core.js line 154 which is otherwise minimized and obfuscated:
function(){eval("var self = arguments[0];"+b)}
I'm not going to argue whether or not eval('...') and new Function('...') are evil/bad practices as the implication from the question is that their usage is blocked anyway in some environments.
As that is the current implementation for the JavaScript API, an alternative is to use the HERE REST API directly for whichever services you need. You will need to handle Ajax requests without the convenience of the JavaScript SDK, but for some libraries and frameworks it may be necessary to have that level of control anyway. We've recently published some blog posts demonstrating this with React, Angular, and Vue that may be helpful examples.

Related

apollo-client in next.js with `next-with-apollo` VS the approach shown in next.js docs FAQ (no use of `getDataFromTree`)

Contrast in "apollo-client in next.js" approaches chosen in next-with-apollo npm library and the approach shown in next.js docs.
The link of approach chosen by next.js for apollo client: https://github.com/vercel/next.js/blob/canary/examples/with-apollo/lib/apolloClient.js
In next.js doc approach:
no third-party library next-with-apollo is used
no get-data-from-tree is used
Moreover i found this approach more meaningful and elegant inner-working of client side redering and SSR of apollo-client in next.js. I strongly like this
Some cons in next-with-apollo approach
in next-with-apollo docs, it is stated that in withApollo API, the parameter getDataFromTree of intialState defaults to undefined by implementaion and its stated "It's recommended to never set this prop, otherwise the page will be a lambda without Automatic Static Optimization "
get-initial-props is used which is not recommended by next.js for optimization reasons
general thing. Why to consider third party library if there is non-third party way and suggested officially unless it has drawbacks?
It made me really curious to see many are using next-with-apollo and rarely seen the usage of the approach shown in next.js docs? I'm curious whether approach in next.js docs has any drawbacks (which i strong think of not having any)?
does the approach shown in next.js has some drawbacks?
does next-with-apollo has more efficiencies? if so what r those more efficiencies for which it is wise not to choose next.js doc approach. I wanna be sure that if i'm rejecting next.js doc approach (currently im choosing it) i'm not doing any wrong
So which is better for both client-side data fetching and server-data fetching to support both CSR and SRR?
I found the answer by posting in next.js community:
Here it goes:
next.js doc's apollo examples avoid using getDataFromTree because it traverses the react tree twice in order to trigger all the queries and collect their result afterwards.
The drawback of using the approach on the next.js doc's apollo examples is since you don't use getDataFromTree, you have no way to know which queries your inner components are using. So you need to remember to prefetch everything you need on getStaticProps/getServerSideProps and match the exact same queries/variables
next.js doc's apollo examples way is recommended instead of getInitialProps so I would always use them unless one has some very specific reason not to

How to use Prerenderio with Meteor?

I would like to use prerenderio with Meteor instead of phantomjs on the server with modulus.
However given the examples they provide, I'm not sure how to integrate it. They only provide a node express middleware which doesn't translate 100%.
For SEO purposes? I mean, what else could it be? ;)
Firstly, remove the spiderable package if you haven't already.
Second, drop this at your server-side code (for example server/prerenderio.js):
// Use Prerender with your token
var prerenderio = Npm.require('prerender-node').set('prerenderToken', 'YOUR_TOKEN');
// Feed it to middleware! (app.use)
WebApp.connectHandlers.use(prerenderio);
If you're wondering about Npm.require (or Meteor.require), See this answer (by me, sorry for shameless plug) for the gist: https://stackoverflow.com/a/16481897/951773
Source: I've used prerenderio successfully for a couple of our clients.
![Good luck!][1]
EDIT:
Since there has been major differences now between express request and response objects to meteor's connect objects, it went to really complicated now. But this has been addressed now and hopefully the PR I put in works:
https://github.com/dfischer/meteor-prerenderio/issues/1
TL;DR Thanks to this question now we have a prerender.io meteor module.

How to create a closure from String in Dart?

How to use dart-mirror API to create a anonymous closure dynamically?
Like as the interpreter, compile the code during run-time.
var funcstr='bool (String s){ return (s==null); }';
var func=parseStr(funcstr);
// func(s)-> s==null;
var r=func('false');
// r=false;
so, how to do with "parseStr"?
my project:
http://github.com/stevehsu77/surebet
At the moment there is no way to do this. Dart has no eval and no code generation at runtime.
But it is something Gilad Bracha (the language spec lead of Dart) wants to have (https://groups.google.com/a/dartlang.org/forum/#!topic/misc/6O4g7eEHgOU) at least for the development environment.
Also
We’d like to support more powerful reflective features in the future. These would include mirror builders, designed to allow programs to extend and modify themselves, and a mirror-based debugging API as well.
https://www.dartlang.org/articles/reflection-with-mirrors/
So it'll probably be supported some time in the future. But right now it's not possible.
As mentioned above, Dart does not have eval, however it is possible to load new source code in another isolate using spawnUri().
I am not sure if there are any examples of how to use this. Perhaps post a message on the dart discussion group.
Using isolates and spawnUri() is quite a different than using eval, so it may not be the right fit for your project.

How to internationalize a handlebars + backbone view?

I would like to be able to internationalize a backbone + Handlebars application but I am not clear what the best way to do it. Are there any specific best practices for internationalizing backbone + Handlebar views?
On the server side I am using SpringMVC and have access to standard java internationalization facilities.
Here are some very good resources on internationalization for the client side.
http://2012.jsconf.eu/speaker/2012/08/28/client-side-internationalization.html really worth watching it provides a good explanation of the issues with internationalization and is java-script focused.
http://alexsexton.com/blog/2012/03/the-ux-of-language/ Good article about the internationalization
JavaScript libraries for internationalization:
https://github.com/SlexAxton/messageformat.js
http://slexaxton.github.com/Jed/
Standards:
http://userguide.icu-project.org/formatparse/messages (very useful read)
http://cldr.unicode.org/ (more of a reference)
Currently I'm working with an app with (very limited) internationalization, and I mix in an object with the model before sending it to the template in the Backbone.Marionette.Renderer.render function. If you have a similar central function which renders your templates (which I assume you have) you can do this logic there. You could for instance mix the internationalized content (language preselected in) in a namespace, for instance
data = _.extend(model, {t: translations(:dutch))
Leaves how to get the translations from the backend to the frontend, but I don't know enough of SpringMVC to give you advise on that.
We use i18next (http://i18next.com) in our Require/Backbone/Handlebars app with very good results. It supports plural and context forms and there are converters from PO to JSON and vice versa. (PO is widely used for translations here.) The documentation is clean and full of helpfull examples.
It's possible to use it in Handlebars with both static keys (strings) or dynamic variables. You will have to setup your own Handlebars helpers but the documentation of i18next provides example code for this.
In this post, I've added more implementation details:
https://stackoverflow.com/a/17728920/621690

Google Geocoding Recommendation

I am looking into utilizing Google Maps API to do some geocoding. I want to implement client side geocoding, to remove the possibility of request limitation.
I need to do some fairly complex logic on the result set, and I would prefer to do that in C# as it is a ASP.NET MVC application. However part of that logic is possibly makeing subsequent follow up requests and that again would require JavaScript.
So, my first thought is to make a service in my application to pass JSON results to and certain return types to trigger the subsequent request. That seems a little convoluted and want to know from the community if this seems like the best approach and if there are any libraries/third party tools that can help handle this situation.
I've an app that does something similar, with the complexity somewhat decoupled by using standardized events (within this app, not a W3 standard or anything)
Client uses native geolocation, SimpleGeo and Google Loader to guess where the user is and AJAX's that to the server.
Server uses client data, MaxMind, and user preferences to decide where to treat the user as being.
Server response is generic event data (as JSON response) that is converted by a generic AJAX response handler into one or more events triggered against the body element.
Depending on the page, various listeners are bound to the events and or namespaces (see jQuery namespaced events) and they handle the updated location events, e.g., getting different weather data, changing local search results
Some of those listeners in turn trigger other AJAX requests, the responses to those may also carry generic events to triggered...
This way there's no sequential code I have to write, i.e., I can add or remove behaviors (simple or complex) without changing anything else. jQuery Events are all I use, really nothing much to it after you decide how you'll pattern things.
Let me know if that's interesting to you and you want me to expand or clarify a part of it.
You may want to try this API:
http://code.google.com/apis/maps/documentation/geocoding/
It's far more REST like - no Javascript required. May work better with C#
In the end I found the best solution was to do as I stated in my question. Pass the JSON object to controller, do work, then return. Worked pretty well.

Resources