Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is `_dereq_()` inside React?

I'm searching through react-0.13.3.js and one thing I can't work out. At the very start of the source there's a bunch of dereq() calls.

'use strict';

var EventPluginUtils = _dereq_(19);
var ReactChildren = _dereq_(32);
var ReactComponent = _dereq_(34);
var ReactClass = _dereq_(33);

But nowhere do I see an implementation for that function. What does it do and how does it work? And most importantly, where is it declared?

Update

I'm still waiting for a more comprehensive answer to accept. My main question is what does the _dereq_ function do and how does it work.

like image 702
Morgan Wilde Avatar asked Jun 04 '15 17:06

Morgan Wilde


3 Answers

This is likely derequire combined with browserify (or other bundler?) module ids. It's a way to rename require in your output bundle so as to avoid collisions.

Read here for more information: https://github.com/calvinmetcalf/derequire/issues/25

The basic idea is that different module loaders handle require differently. "Derequire" is a strategy for binding your requires to your context via a different keyword.

like image 123
glortho Avatar answered Oct 19 '22 18:10

glortho


It has to do with amd module loader. _dereq_ is the first argument so it's the require function.

like image 1
Halcyon Avatar answered Oct 19 '22 17:10

Halcyon


You need to expand line 4 in the source; it's require.

1: [function(_dereq_, module, exports) {
like image 1
Mathletics Avatar answered Oct 19 '22 17:10

Mathletics