Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I believe reactive programming is considerably hidden, especially in imperative languages. It's an amazingly powerful programming paradigm, especially in Node.js. Meteor has created it's own reactive engine in which the framework is basically based upon. How does Meteor's reactivity work behind the scenes?How does Meteor's reactivity work behind the scenes? is a great overview of how it works internally.

I believe reactive programming is considerably hidden, especially in imperative languages. It's an amazingly powerful programming paradigm, especially in Node.js. Meteor has created it's own reactive engine in which the framework is basically based upon. How does Meteor's reactivity work behind the scenes? is a great overview of how it works internally.

I believe reactive programming is considerably hidden, especially in imperative languages. It's an amazingly powerful programming paradigm, especially in Node.js. Meteor has created it's own reactive engine in which the framework is basically based upon. How does Meteor's reactivity work behind the scenes? is a great overview of how it works internally.

fixed tyop
Source Link
zzzzBov
  • 5.8k
  • 1
  • 30
  • 28

First of all, eval() isn't always bad, and can bring benefit in performance when used in lazy-evaluation, for example. Lazy-evaluation is similar to lazy-loading, but you essentially store your code within strings, and then use eval or new Function to evaluate the code. If you use some tricks, then it'll become much more useful thenthan evil, but if you don't, it can lead to bad things. You can look at my module system that uses this pattern: https://github.com/TheHydroImpulse/resolve.js. Resolve.js uses eval instead of new Function primarily to model the CommonJS exports and module variables available in each module, and new Function wraps your code within an anonymous function, though, I do end up wrapping each module in a function I do it manually in combination with eval.

First of all, eval() isn't always bad, and can bring benefit in performance when used in lazy-evaluation, for example. Lazy-evaluation is similar to lazy-loading, but you essentially store your code within strings, and then use eval or new Function to evaluate the code. If you use some tricks, then it'll become much more useful then evil, but if you don't, it can lead to bad things. You can look at my module system that uses this pattern: https://github.com/TheHydroImpulse/resolve.js. Resolve.js uses eval instead of new Function primarily to model the CommonJS exports and module variables available in each module, and new Function wraps your code within an anonymous function, though, I do end up wrapping each module in a function I do it manually in combination with eval.

First of all, eval() isn't always bad, and can bring benefit in performance when used in lazy-evaluation, for example. Lazy-evaluation is similar to lazy-loading, but you essentially store your code within strings, and then use eval or new Function to evaluate the code. If you use some tricks, then it'll become much more useful than evil, but if you don't, it can lead to bad things. You can look at my module system that uses this pattern: https://github.com/TheHydroImpulse/resolve.js. Resolve.js uses eval instead of new Function primarily to model the CommonJS exports and module variables available in each module, and new Function wraps your code within an anonymous function, though, I do end up wrapping each module in a function I do it manually in combination with eval.

Bounty Awarded with 150 reputation awarded by CommunityBot
added 2067 characters in body
Source Link
Daniel
  • 1.9k
  • 2
  • 15
  • 14

Harmony Generators

Now that generators have finally landed in V8 and thus in Node.js, under a flag (--harmony or --harmony-generators). These greatly reduce the amount of callback hell you have. It makes writing asynchronous code truly great.

The best way to utilize generators is to employ some sort of control-flow library. This will enable to flow to continue going as you yield within generators.

Recap/Overview:

If you're unfamiliar with generators, they're a practice of pausing the execution of special functions (called generators). This practice is called yielding using the yield keyword.

Example:

function* someGenerator() {
  yield []; // Pause the function and pass an empty array.
}

Thus, whenever you call this function the first time, it'll return a new generator instance. This allows you to call next() on that object to start or resume the generator.

var gen = someGenerator();
gen.next(); // { value: Array[0], done: false }

You would keep calling next until done returns true. This means the generator has completely finished it's execution, and there are no more yield statements.

Control-Flow:

As you can see, controlling generators are not automatic. You need to manually continue each one. That's why control-flow libraries like co are used.

Example:

var co = require('co');

co(function*() {
  yield query();
  yield query2();
  yield query3();
  render();
});

This allows the possibility to write everything in Node (and the browser with Facebook's Regenerator which takes, as input, source code that utilize harmony generators and splits out fully compatible ES5 code) with a synchronous style.

Generators are still pretty new, and thus requires Node.js >=v11.2. As I'm writing this, v0.11.x is still unstable and thus many native modules are broken and will be until v0.12, where the native API will calm down.


Harmony Generators

Now that generators have finally landed in V8 and thus in Node.js, under a flag (--harmony or --harmony-generators). These greatly reduce the amount of callback hell you have. It makes writing asynchronous code truly great.

The best way to utilize generators is to employ some sort of control-flow library. This will enable to flow to continue going as you yield within generators.

Recap/Overview:

If you're unfamiliar with generators, they're a practice of pausing the execution of special functions (called generators). This practice is called yielding using the yield keyword.

Example:

function* someGenerator() {
  yield []; // Pause the function and pass an empty array.
}

Thus, whenever you call this function the first time, it'll return a new generator instance. This allows you to call next() on that object to start or resume the generator.

var gen = someGenerator();
gen.next(); // { value: Array[0], done: false }

You would keep calling next until done returns true. This means the generator has completely finished it's execution, and there are no more yield statements.

Control-Flow:

As you can see, controlling generators are not automatic. You need to manually continue each one. That's why control-flow libraries like co are used.

Example:

var co = require('co');

co(function*() {
  yield query();
  yield query2();
  yield query3();
  render();
});

This allows the possibility to write everything in Node (and the browser with Facebook's Regenerator which takes, as input, source code that utilize harmony generators and splits out fully compatible ES5 code) with a synchronous style.

Generators are still pretty new, and thus requires Node.js >=v11.2. As I'm writing this, v0.11.x is still unstable and thus many native modules are broken and will be until v0.12, where the native API will calm down.


added 1203 characters in body
Source Link
Daniel
  • 1.9k
  • 2
  • 15
  • 14
Loading
deleted 2 characters in body
Source Link
Daniel
  • 1.9k
  • 2
  • 15
  • 14
Loading
added 2 characters in body
Source Link
Daniel
  • 1.9k
  • 2
  • 15
  • 14
Loading
added 2 characters in body
Source Link
Daniel
  • 1.9k
  • 2
  • 15
  • 14
Loading
edited body
Source Link
Daniel
  • 1.9k
  • 2
  • 15
  • 14
Loading
Mod Removes Wiki by yannis
added 1242 characters in body
Source Link
Daniel
  • 1.9k
  • 2
  • 15
  • 14
Loading
added 2 characters in body
Source Link
Daniel
  • 1.9k
  • 2
  • 15
  • 14
Loading
added 684 characters in body
Source Link
Daniel
  • 1.9k
  • 2
  • 15
  • 14
Loading
Bounty Awarded with 50 reputation awarded by gnat
added 1977 characters in body
Source Link
Daniel
  • 1.9k
  • 2
  • 15
  • 14
Loading
added 1977 characters in body
Source Link
Daniel
  • 1.9k
  • 2
  • 15
  • 14
Loading
added 1082 characters in body
Source Link
Daniel
  • 1.9k
  • 2
  • 15
  • 14
Loading
added 1096 characters in body
Source Link
Daniel
  • 1.9k
  • 2
  • 15
  • 14
Loading
added 1096 characters in body
Source Link
Daniel
  • 1.9k
  • 2
  • 15
  • 14
Loading
added 331 characters in body
Source Link
Daniel
  • 1.9k
  • 2
  • 15
  • 14
Loading
added 331 characters in body
Source Link
Daniel
  • 1.9k
  • 2
  • 15
  • 14
Loading
added 694 characters in body
Source Link
Daniel
  • 1.9k
  • 2
  • 15
  • 14
Loading
added 694 characters in body
Source Link
Daniel
  • 1.9k
  • 2
  • 15
  • 14
Loading
Source Link
Daniel
  • 1.9k
  • 2
  • 15
  • 14
Loading