Integrate PouchDB with quick search search plugin - npm

I'm using PouchDB and trying to add pouchdb-quick-search as plugin in npm way like described in it:
var PouchDB = require('pouchdb');
PouchDB.plugin(require('pouchdb-quick-search'));
But no success: search function is undefined.
Have anyone deal with it?

It works for me. I created a file called index.js containing:
var PouchDB = require('pouchdb');
PouchDB.plugin(require('pouchdb-quick-search'));
var db = new PouchDB('mydb');
console.log('db.search: ' + db.search);
Then I ran from the command line:
npm install pouchdb && npm install pouchdb-quick-search
node index.js
And it printed out:
db.search: function () {
var len = arguments.length;
var args = new Array(len);
var i = -1;
while (++i < len) {
args[i] = arguments[i];
}
return fun.call(this, args);
}
I'm using Node v4.0.0 on Mac OS X. Let me know if that helps.

Related

How to write a JSON file into the dist folder by vue.config.js webpack config?

The origin data is not from a file, but from a JSON object.
I already know how to use the native Node.js code to write a JSON file into the dist directory, but now I want to use vue.config.js webpack config to do this task.
I'm not familiar with webpack either. I simply checked some information, but I didn't find any way.
I hope to get some advice, thanks!
I found a solution.
const fs = require('fs-extra');
function JsonWebpackPlugin() {
fs.writeJSONSync('./public/some.json', { a: 1 });
}
JsonWebpackPlugin.prototype.apply = new Function();
module.exports = {
chainWebpack(config) {
config.plugin('Json').use(JsonWebpackPlugin);
}
}

TestCafe: Changing download location

I am trying to change the download location and I found these codes doing research (sorry I forgot where I got these)
const browserConnection = t.testRun.browserConnection;
const client = browserConnection.provider.plugin.openedBrowsers[browserConnection.id].client;
const { Network, Page } = client;
const downloadDirectory = '../my_downloads');
await Promise.all([
Network.enable(),
Page.enable()
]);
Network.requestWillBeSent((param) => {
// console.log("Network.requestWillBeSent: " + JSON.stringify(param));
});
Network.responseReceived((param) => {
// console.log("Network.responseReceived: " + JSON.stringify(param));
});
await Page.setDownloadBehavior({
behavior: 'allow',
downloadPath: downloadDirectory
});
It was working perfectly fine using version 10.9.2 and this version was installed globally. I updated my TestCafe to 1.10.1 locally installed and now got this error:
TypeError: Cannot destructure property 'Network' of 'client' as it is undefined.
Any inputs are well appreciated. And looking forward to it :)
This internal API has changed due to testing support of multiple windows. Please use the getActiveClient method:
const browserConnection = t.testRun.browserConnection;
const runtimeInfo = rowserConnection.provider.plugin.openedBrowsers[browserConnection.id];
const { Network, Page } = await runtimeInfo.browserClient.getActiveClient();
If you need to change the download location to read and check a file from it, please use a public API for this: example.

Ignoring a new file with vue's dev server

I'm using the pre-build-webpack plugin to merge several json files into 1 json array every time I start my app (npm run serve or npm run build), but the problem is that it gets caught in an infinite webpack compile loop in when I start the development server. I managed to find a solution to the problem by using the watch-ignore-webpack-plugin plugin, which initially seemed to have resolved the issue - webpack will now compile everything twice (it seems) and then it's good to go and I can access my local server. But the problem now is that when I visit localhost:8080 there's nothing. The screen's blank and there's nothing being console.log()ed, so I don't know what to do anymore.
If anyone's seen anything like this or know how to fix it, please let me know. If you require any additional info, also let me know.
Versions:
vue: 2.6.10 (as seen in package.json)
vue-cli: 3.11.0 (running vue -V in cmd)
pre-build-webpack: 0.1.0
watch-ignore-webpack-plugin: 1.0.0
webpack-log: 3.0.1
vue.config.js (with everything irrelevant removed):
const WebpackPreBuildPlugin = require('pre-build-webpack');
const WatchIgnorePlugin = require('watch-ignore-webpack-plugin');
module.exports = {
configureWebpack: {
plugins: [
new WebpackPreBuildPlugin(() => {
const fs = require('fs');
const glob = require('glob');
const log = require('webpack-log')({ name: 'ATTENTION!' });
const output = [];
const exclude = [];
glob('./src/components/mods/**/*.json', (err, paths) => {
paths.forEach(path => {
const content = JSON.parse(fs.readFileSync(path, 'utf-8'));
const pathSplit = path.split('/');
const modFolderName = pathSplit[pathSplit.length - 2]
if(!output.filter(val => val.id === content.id)[0]) {
if(exclude.indexOf(modFolderName) === -1) {
output.push(content);
} else {
log.warn(`SKIPPING CONTENTS OF "${modFolderName}"`);
}
} else {
log.error(`MOD WITH ID "${content.id}" ALREADY EXISTS!`);
process.exit(0);
}
});
// If I take out this line, the infinite loop doesn't occur, but then, of
// course, I don't get my merged json file either.
fs.writeFileSync('./src/config/modules/layoutConfig.json', JSON.stringify(output));
});
}),
// Neither of the blow paths work.
new WatchIgnorePlugin([/\layoutConfig.json$/]),
// new WatchIgnorePlugin(['./src/config/modules/layoutConfig.json']),
]
}
};

Using react native with Optimizely

I try to follow documentation in Optimizely to get my react native app (#22.2) working but getting such bug.
MainActivity.java:24: error: cannot find symbol
Optimizely.startOptimizelyWithApiToken("xxxxxx", getApplication());
^
symbol: method startOptimizelyWithApiToken(String,Application)
location: class Optimizely
1 error
:app:compileDebugJavaWithJavac
What is wrong and how can I debug . I try
adb logcat ReactNative:V ReactNativeJS:V
but it's not giving me any information
I an on the engineering team at Optimizely and we've released a brand new product called FullStack that is more geared towards developers. As part of the product we now offer a JavaScript SDK for running experiments in all JavaScript clients, including React Native.
To use you would install our SDK:
npm install optimizely-client-sdk
And then you can split traffic using our activate and track methods.
Here is an example:
var optimizely = require('optimizely-client-sdk');
// Initialize an Optimizely client
var optimizelyClientInstance = optimizely.createInstance({ datafile: datafile });
// ALTERNATIVELY, if you don't use CommonJS or npm, you can install the minified snippet and use the globally exported varible as follows:
var optimizelyClientInstance = window.optimizelyClient.createInstance({ datafile: datafile });
// Activate user in an experiment
var variation = optimizelyClientInstance.activate("my_experiment", userId);
if (variation === 'control') {
// Execute code for variation A
} else if (variation === 'treatment') {
// Execute code for variation B
} else {
// Execute default code
}
// Track conversion event
optimizelyClientInstance.track("my_conversion", userId);
For more information please checkout our developer docs: https://developers.optimizely.com/x/solutions/sdks/introduction/index.html?language=javascript
i sorted problem is more about reading docs and using legacy:
compile ('com.optimizely:optimizely-legacy:+#aar') {
transitive = true
}
and then:
Optimizely.startOptimizely("xxxx", getApplication());

List files from browserify bundle

How can I see a list of all files found and bundled using the API, much like browserify's --list command-line option?
var browserify = require('browserify');
var b = browserify('main.js').bundle();
You can listen to the dep event, which is triggered for every dependency going through the pipeline:
var b = browserify('main.js');
b.on('dep', function(dep) {
console.log(dep.file);
});
b.bundle();
Got it, not a direct solution but the only foreseeable one.
When browserify('main.js').bundle() is called, browserify looks recursively through each of the required files and triggers any stream handlers set via b.pipeline.get('deps').push() when each file is found/read.
var dependencies = '';
b.pipeline.get('deps').push(through.obj(function(row, enc, next) {
dependencies += (row.file || row.id) + '\n';
this.push(row);
next();
}));