wearereasonablepeople / couchify Goto Github PK
View Code? Open in Web Editor NEWuse next generation JS in your CouchDB apps
License: MIT License
use next generation JS in your CouchDB apps
License: MIT License
Cases:
view
dependencies from the restreduce
See: client.ts
Lines 10 to 12 in 45e8ad8
The output json for the view when outputting dry mode into a file looks like this
{
"map": " (function(){\n\nreturn function (doc) {\n\n if (doc.amp && (doc.at || doc.until)) {\n var date = doc.until || doc.at;\n emit(doc.amp, new Date(date.time + date.offset).getTime());\n }\n };\n\nvar reduce = exports.reduce = function reduce() {\n return function (keys, values) {\n return Math.max(values);\n };\n};\n\n}())",
"reduce": " (function(){\n\nvar map = exports.map = function map(_ref) {\n var emit = _ref.emit;\n return function (doc) {\n\n if (doc.amp && (doc.at || doc.until)) {\n var date = doc.until || doc.at;\n emit(doc.amp, new Date(date.time + date.offset).getTime());\n }\n };\n};\n\nreturn function (keys, values) {\n return Math.max(values);\n };\n\n}())"
},
So the map function ends up with the reduce function in the body and vice versa.
This is the source for the view
export const map = ({emit}) => doc => {
if(doc.amp && (doc.at || doc.until)) {
const date = doc.until || doc.at;
emit(doc.amp, new Date(date.time + date.offset).getTime());
}
};
export const reduce = () => (keys, values) => Math.max(values);
And it gets transpiled to
(function(){
var map = exports.map = function map(_ref) {
var emit = _ref.emit;
return function (doc) {
if (doc.amp && (doc.at || doc.until)) {
var date = doc.until || doc.at;
emit(doc.amp, new Date(date.time + date.offset).getTime());
}
};
};
return function (keys, values) {
return Math.max(values);
};
}())
And
(function(){
return function (doc) {
if (doc.amp && (doc.at || doc.until)) {
var date = doc.until || doc.at;
emit(doc.amp, new Date(date.time + date.offset).getTime());
}
};
var reduce = exports.reduce = function reduce() {
return function (keys, values) {
return Math.max(values);
};
};
}())
CouchDB does not support require()
calls in reduce
functions.
We can inline everything into a single bundle for only reduce
functions.
module-deps
accepts the same transform format Browserify uses.
Some examples:
require()
outside the body of design functionsFigure out how to use eslint-config-warp
with TSLint.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.