Load latest version of a Google API? - javascript

I'm not sure how to preface this. I'm working on an angular wrapper for the Google Client API (note: I'm doing this simply because I haven't found anything that works for me, so if you know of a Google API / Angular, let me know)
I'm trying to make this as generic as possible, so what I would like is something like a function that goes
function makeApiCall (library, collection, method, cb){
gapi.client[library][collection][method](
}
Now if we notice, I'm not checking that the library has been loaded, and I'd like to load the library if it hasn't been already. Problem is that not all libraries from Google have the same version, and as of right now I do not know of a way to check the latest version.
I've tried somethings like the following
gapi.client.load('calendar', 'latest', cb);
gapi.client.load('calendar', 'release', cb);
I remember a long time ago you could use ... well one of those (can't remember which). Is there some way to do this now? Otherwise I'll have to figure something else out.

Related

Need Example Using #wordpress/hooks In Node Program

I'd like to add the ability to hook into a Node.js program I am writing for release. Ideally, I'd like something like the Wordpress Hook system (traditionally for PHP and recently for Javascript!) that is very robust, yet simple.
It seems WP has released a Node module for just this purpose: https://www.npmjs.com/package/#wordpress/hooks
However, I can find no documentation or real-world examples explaining how exctly to implement this.
Lets say I have a function that does this:
function processObj(myObj){
doThing1(myObj);
doThing2(myObj);
// I want to allow plugin writers to add a Thing3, Thing4, etc...
return myObj;
}
I believe this is a filter... As in I want to allow plugins to filter myObj through Thing3 (which they create) before the return. But I'm lost as to how to implement.

Dependency tracking modules from a concatenated library

What I've got
A large (proprietary unfortunately) JS library, the many small modules that get rolled up into it during the build process, the accompanying source map, and over 300 examples that use the built version of the library.
The goal
A form of dependency tracking, I guess? I need to be able to modify one of the small modules, rebuild the large file, and then only re-verify the examples that were affected by this change. Note: I don't care whether this requires static analysis or if I have to run all examples thru a headless browser to extract something or so - I'm fine as long as it can be automated.
What I've tried so far
I've read answers to questions like this and tried pre-existing tools like
Madge, but none of them seem to work for my case. Madge in particular is great for telling me which of the modules depend on which modules, but that's not what I'm looking for. Most solutions online are based on the assumption that you're already using something like require.js or similar on which they can piggy-back, but in my case the library is simply just a giant blob.
My current approach is instrumenting the built version of the library by simply appending every line with something like neededModules["the_file_this_line_comes_from.module.js"] = true similar to how code coverage tools do it. However, that fails because of several parts like this:
Points.prototype = Object.assign( Object.create( Info.prototype ), {
plot: ( function () {
var static = new Background();
return function plot( line, physics ) {
<code>
};
}() ),
copy: function () {
return new this.constructor( this.info, this.history ).copy( this );
}
} );
The copy function is tracked/skipped just fine, but because the plot function is an IIFE(right?), the line var static = new Background(); always gets executed, even if there is absolutely no connection to the Points module.
What I'm looking for
Either some help with my current approach and its problems with IIFE or a different solution altogether. I've seen Facebook's Jest does offer dependency tracking, maybe someone has experience with that one, or there's some way to incorporate the source map?
Again, as long as it's automatable and finishes in let's say < 5 min, I'm totally fine with it no matter if it's static analysis or just some hacky script or whatever :)
Thanks!

Call Electron method from Frontend

I'm trying to figure out how to call an Electron method from my frontend application javascript. Either the main or renderer process would do fine for starters, presumably I can work through the rest from there.
In all the examples I can find, the renderer code attaches to the frontend element and adds an event listener:
document.querySelector('#btn').addEventListener(() => { // doElectronStuff });
This is not quite what I'm after though... it seems like a rather severe coupling to have this "server side" code reaching into my DOM.
Using an Angular2 frontend, I found what appears to be a nice package called ngx-electron which exposes the electron interface as an injectable complete with typescript mappings, etc.
So now I have an Angular service that I want to call an Electron method for (to grab some database stuff, or whatever else):
constructor(private _electron:ElectronService) {}
getAll(): Entity[] {
var results = this._electron.ipcRenderer.?????
}
I really have no idea how to make the angular service make that call to the electron method. I've tried running emit() and have tried using send() and such against the ipcRenderer, the remote.ipcMain, but receive various errors and all and all can't seem to make the connection.
Hopefully I missing something simple? What's the combination of electron-side syntax and angular-side syntax that's required to match these up? Thanks
(I'm not particularly stuck on ngx-electron, but it did seem a nice lib and I'm assuming it works well, once I get past my own block...)
Found it. As usual, an oversight on my end.
// in the angular service
this._electron.ipcRenderer.send('event-aka-channel-name1', args);
// in the electron main.js
ipc.on('event-aka-channel-name1', (event, args) => { // doStuff });
My issue was apparently a misspelling of an import which I caught via various logs. Once that was fixed the rest works as intended (or at least enough for me to move forward)

Ember and Syn integration

I'm having trouble integrating bitovi syn (link), Rails 3 (asset pipeline), Ember and qunit. I want to use syn for browser simulation for testing purposes. Has anyone done this, if so, how?
I'm using the version of syn that was released 11 Mar 2014. When I load it into my app, two things happen:
I get a global failure in qunit that says "TypeError: 'undefined' is not an object (evaluating 'Syn.schedule')", (around this line: syn.js?body=1:1084)
and
A div with a form is added to my application.
I'm using qunit for the most part, and I dabbled with using YUI to do browser simulation but it isn't working quite the way I had expected it to. I'd really like to use Syn, but I don't understand why it's not working.
In attempting to get it work, I tried adding this line to the top of the syn.js file:
window.Syn = { schedule: function (fn, ms) { Ember.run.later(window, fn, ms); } };
but it didn't do anything much at all.
I'd read on this pull request: https://github.com/bitovi/syn/pull/28 that I could add that piece of code to mount it in a fashion to work with Ember.
Any help would be greatly appreciated!
So the thing here was simply to load Syn at the bottom of the page. It's potentially a bit broken at the moment in the case where you want to load it in the head (which I probably shouldn't have been doing anyway, but still!) :)

How to load timezone files with timezone-js without Fleegix.js?

I want to use timezone-js in my app, but I'm not Fleegix.js, which "just works". The readme says to look in the spec file for an example, but it looks like that uses Node.js stuff. Is there a way to make a load for Jquery or just raw JS or something?
I got confused on those docs also. It's not quite clear, but jQuery support is already built in. You just have to set async to false to get it to work. Not sure why - since ajax is async anyway - but that's the flag to set to get it to work with jQuery. No other wireup is needed.
timezoneJS.timezone.zoneFileBasePath = 'scripts/tz';
timezoneJS.timezone.init({ async: false });
Also - there are other libraries that do the same thing. You may find one of these more appealing.

Categories