In Meteor 1.4, what's the difference between these two import statements in the client code and in the server code? Why?
Client code:
import { Items } from '../imports/api/items.js';
Server code:
import '../imports/api/items.js';
Both statements will execute the file given, however the first one will add Item to the scope. This can be useful if the file has many exports and you are only concerned with that single class/function/object/etc.
The second is used for side effects provided from importing it (like initializing a store or something like that; I confess I don't know much about meteor).
Mozilla has a great resource on the import statement https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
Related
Recently I've been trying to learn testing, and everything makes sense but I'm running into how to test my specific application. A lot of my front-end JS functions interact with the DOM, which makes JSDOM and Selenium a good candidate. I use ES6 modules on my application, and one of the JS modules is easy to test because everything is wrapped in functions, and even if a function does use the DOM, I could always replicate the behavior with JSDOM. This is how that module looks.
/* simple-module.js */
// does not use DOM on load :)
const myFunc = () => {
document.querySelector(".aDiv").innerHTML = "DOM is accessed on function call";
}
Another module however, I'm having issues with.
/* troublesome-module.js */
let div = document.querySelector(".aDiv");
div.innerHTML = "this is all happening as soon as the module is loaded";
const myFunc = () => {
div.innerHTML = "this happens on function call";
}
As you can see, the DOM is used as soon as the module is loaded.
This is what my test file looks like and why I'm running into issues.
/* test.js */
import * as assert from "assert";
import chromedriver from 'chromedriver';
import * as JSDOM from "jsdom";
import * as webdriver from "selenium-webdriver";
import * as troubleSomeMod from "../troublesome-module.js";
When I run this file, I obviously get an error from 'troublesome-module.js' that there is no such 'document' object. My first thought is to use selenium to load the main webpage, assign global.document to selenium's environment, do the same for global.window, then I can import 'troublesome-module.js' and the DOM will already be replicated. That falls apart when I realized I imports have to be the top level in a JS document.
Is there a way I could load the selenium environment, load the modules, and then appropriately test the functions in the modules? If not, I can always use selenium to completely replicate a user and test that way, however testing individual functions seems more robust to changes. Thank you if you read this far :), any help is appreciated.
Let's say I have the current Firestore data:
COLLECTION_1
DOC_A
DOC_B
DOC_C
COLLECTION_2
DOC_X
And I have some exported data, which is:
COLLECTION_1
DOC_B // DOC_A IS NOT HERE
DOC_C
DOC_D // DOC_D IS AN "EXTRA"
// COLLECTION_2 IS MISSING
COLLECTION_3 // THERE IS AN "EXTRA" COLLECTION
DOC_3
What happens when I import data data? Will some kind of "merge" occur, or my entire Firestore will be replaced with the imported data as is? I'm gessing DOC_D and COLLECTIO_3 will be added for sure. But will DOC_A and COLLECTION_2 (the ones missing on the exported data) still be there after the import?
PS: I'm asking this on the context of a full import (i.e: all collections).
To import specific collections, it seems that you need to use an export that exported specific collections, and you need to import it back using gcloud. The web console only allows for full imports. Anyway, I think the global "merge or override" behavior on a full import is probably similar to the same behavior over a specific collection.
Docs on import/export
This was super quick to test it. The result is
COLLECTION_1
DOC_A
DOC_B
DOC_C
DOC_D
COLLECTION_2
DOC_X
COLLECTION_3
DOC_3
Everything is happening by document. Mentioned documentation says:
If a document with the same ID already exists, the import overwrites
the existing document.
If a document in your database is not affected by an import, it will
remain in your database after the import.
And this exactly happening. Documents that are exist in the import are overridden, and not existing are added. If document is in Firestore but not in import it remains unchanged.
BTW if you test it in GUI, you have to refresh the page after import. Otherwise changes are not visible (at least it happened to me).
I read that Openrefine Wikidata import can only create statements with rank = Normal.
I am in a situation where I would like to import deprecated identifiers, namely old ISSNs (identifiers for serial publications) that used to be used to refer to a publication, but that are no longer in use. They have value because other bibliographic databases might still use them to refer to a publication.
So I'd like to be able to import these values, and mark them as "deprecated".
OpenRefine Wikidata import really really can't do that ? any workaround I could use ?
If I can't do that by the time I import the data from OpenRefine, I can flag these statements with "reason for deprecation = withdrawn identifier value". Can I run another automated process after import that would automatically set a deprecated rank on these statements ?
If I can't set them automatically to deprecated neither at import time nor after, which other qualifier can I use to indicated these identifiers are no longer in use ? (the official term being "Cancelled ISSN")
Thanks
A possibility I found would be to use the Wikidata-Toolkit library, in which StatementBuilder can create Statements with a specified rank. I would still to know/fetch the list of statements to modify...
I am still open to suggestions on the possibility to specify ranks at import time.
I'm just getting started with Flow, trying to introduce it into an existing Node codebase.
Here are two lines Flow complains about:
import Module from 'module';
const nodeVersion = Number(process.versions.node.split('.')[0]);
The warnings about these lines are, respectively:
module. Required module not found
call of method `split`. Method cannot be called on possibly null value
So it seems like Flow isn't aware of some things that are standard in a Node environment (e.g. process.versions.node is guaranteed to be a string, and there is definitely a Node builtin called module).
But then again, Flow's configuration docs suggest it's Node-aware by default. And I have plenty of other stuff like import fs from 'fs'; which does not cause any warning. So what am I doing wrong?
Module fs works as expected because Flow comes with built-in definitions for it, see declare module "fs" here: https://github.com/facebook/flow/blob/master/lib/node.js#L624
Regarding process.versions.node, you can see in the same file that the versions key is typed as a map of nullable strings, with no mention of the specific node property: versions : { [key: string] : ?string };. So you'll need to either make a PR to improve this definition, or adjust your code for the possibility of that value being null.
I guess the answer about module "module" is obvious now – there are no built-in definitions for that module in Flow in lib/node.js. You could write your own definitions, and optionally send a PR with them to the Flow team. You can also try searching github for these, someone might have done the work already.
That lib directory is very useful by the way, it has Flow definitions for DOM and other stuff as well.
I am writing a Python/PyQt4 application that generates and displays a page in a QWebView widget. The page includes javascript code that I would like to be able to call functions returning data from the python application.
So far I can call functions that do not return data (using the pyqtSlot decorator), and call functions that do take parameters by exposing them as properties (using the pyqtProperty decorator). What I haven't worked out how to do is to call a python function with parameters, that returns data.
The question 9615194 explains how to do this from C++, but I cannot see how to transfer this to PyQt4.
I suspect you're not using the result= keyword to specify the return value in your pyqtSlot decorator?
#pyqtSlot(str, result=str)
def echo(self, phrase):
return self.parent().echo(phrase)
I ran afoul of this myself recently. No errors are generated if you omit result=, the method just silently returns nothing. Pretty maddening 'til I figured it out. See my answer to this question for a worked example.