Skip to content

Commit a387f75

Browse files
author
Ian MacLeod
committed
Convert existing logic over to AMD-style defines
1 parent b62b882 commit a387f75

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+154
-150
lines changed

PRIMER.md

+2
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ This user is a manager.
291291
<a name="module-registry"></a>
292292
## Module registry
293293

294+
TODO(nevir): Document `define` and friends.
295+
294296
Polymer provides and internally uses a JavaScript "module registry" to organize library code defined outside the context of a custom element prototype, and may be used to organize user code when convenient as well. The registry is responsible for storing and retrieving JS modules by name. As this facility does not provide dependency loading, it is the responsibility of the user to HTMLImport files containing any dependent modules before use.
295297

296298
Modules are registered using the `modulate` global function, passing a name to register and a factory function that returns the module:

polymer-micro.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<script>
1919

20-
using('Base', function(Base) {
20+
define(['Base'], function(Base) {
2121

2222
Base.addFeature({
2323

polymer-mini.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<script>
1919

20-
using('Base', function(Base) {
20+
define(['Base'], function(Base) {
2121

2222
Base.addFeature({
2323

polymer.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<script>
2222

23-
using('Base', function(Base) {
23+
define(['Base'], function(Base) {
2424

2525
Base.addFeature({
2626

src/expr/polymer-expr.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<script>
2222

23-
using('Base', function(Base) {
23+
define(['Base'], function(Base) {
2424

2525
Base.addFeature({
2626

src/expr/resolveUrl.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
99
-->
1010
<script>
11-
using(['Base'], function(Base) {
11+
define(['Base'], function(Base) {
1212

1313
var domModule = document.createElement('dom-module');
1414

src/expr/x-styling-defaults.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<link rel="import" href="../lib/style-util.html">
1111
<script>
1212

13-
modulate('StyleDefaults', ['Base', 'StyleUtil'], function(Base, styleUtil) {
14-
13+
define('StyleDefaults', ['Base', 'StyleUtil'], function(Base, styleUtil) {
14+
1515
Base.addFeature({
1616

1717
// TODO(sorvell): decide if this fits; an element can supply

src/expr/x-styling.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<link rel="import" href="../lib/shadow-settings.html">
1313
<link rel="import" href="x-styling-defaults.html">
1414
<script>
15-
using(['Base', 'StyleTransformer', 'StyleUtil', 'ShadowSettings', 'StyleDefaults'],
15+
define(['Base', 'StyleTransformer', 'StyleUtil', 'ShadowSettings', 'StyleDefaults'],
1616
function(Base, transformer, styleUtil, settings, defaults) {
1717

1818
var beforeReady = Base._beforeReady;

src/features/micro/attributes.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
*
5151
* @class base feature: attributes
5252
*/
53-
54-
using('Base', function(Base) {
53+
54+
define(['Base'], function(Base) {
5555

5656
Base.addFeature({
5757

src/features/micro/constructor.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* @class base feature: constructor
3737
*/
3838

39-
using('Base', function(Base) {
39+
define(['Base'], function(Base) {
4040

4141
Base.addFeature({
4242

src/features/micro/extends.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
* @class base feature: extends
2727
*/
2828

29-
using('Base', function(Base) {
30-
29+
define(['Base'], function(Base) {
30+
3131
Base.addFeature({
3232

3333
_prepExtends: function() {

src/features/micro/mixins.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
-->
1010
<script>
1111

12-
using('Base', function(Base) {
12+
define(['Base'], function(Base) {
1313

1414
/**
1515
* Automatically extend using objects referenced in `mixins`
@@ -39,7 +39,9 @@
3939
var host = this;
4040
this.mixins.forEach(function(m) {
4141
if (typeof m === 'string') {
42-
using(m, function(m) {
42+
// TODO(nevir): Switch this to local (or global?) `require` once
43+
// we have that.
44+
define([m], function(m) {
4345
Base.extend(host, m);
4446
});
4547
} else {

src/features/micro/published.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<script>
1111

1212

13-
using('Base', function(Base) {
13+
define(['Base'], function(Base) {
1414

1515

1616
/**

src/features/mini/content.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<link rel="import" href="../../lib/array-splice.html">
1111
<script>
1212

13-
using(['Base', 'ArraySplice'], function(Base, ArraySplice) {
13+
define(['Base', 'ArraySplice'], function(Base, ArraySplice) {
1414

1515
/**
1616

src/features/mini/ready.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* @class standard feature: ready
3131
*/
3232

33-
using('Base', function(Base) {
33+
define(['Base'], function(Base) {
3434

3535
hostStack = [];
3636

src/features/mini/shadow.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
-->
1010
<link rel="import" href="../../lib/shadow-settings.html">
1111
<script>
12-
13-
using(['Base', 'ShadowSettings'], function(Base, settings) {
12+
13+
define(['Base', 'ShadowSettings'], function(Base, settings) {
1414

1515
/**
1616
Implements `shadyRoot` compatible dom scoping using native ShadowDOM.

src/features/mini/template.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
*
2222
* @class standard feature: template
2323
*/
24-
25-
using('Base', function(Base) {
24+
25+
define(['Base'], function(Base) {
2626

2727
var domModule = document.createElement('dom-module');
2828

src/features/standard/annotations.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
114114
*/
115115

116-
using(['Base', 'Annotations'], function(Base, Annotations) {
116+
define(['Base', 'Annotations'], function(Base, Annotations) {
117117

118118
Base.addFeature({
119119

src/features/standard/configure.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
directly (on-foo-changed).
4242
*/
4343

44-
using(['Base'], function(Base) {
44+
define(['Base'], function(Base) {
4545

4646
Base.addFeature({
4747

src/features/standard/effects.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
* @class data feature: bind
8585
*/
8686

87-
using(['Base', 'bind', 'bind-annotations'],
87+
define(['Base', 'bind', 'bind-annotations'],
8888
function(Base, Bind, BindAnnotations) {
8989

9090
Base.addFeature({

src/features/standard/events.html

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
-->
1010
<script>
1111

12+
// TODO(nevir): We should expose these constants directly on `Polymer`, or
13+
// maybe implement AMD's global `require()`.
1214
/**
1315
* Supports `listeners` and `keyPresses` objects.
1416
*
1517
* Example:
16-
*
17-
* using('Base', function(Base) {
18-
*
18+
*
19+
* define(['Base'], function(Base) {
20+
*
1921
* Polymer({
2022
*
2123
* listeners: {
@@ -38,7 +40,7 @@
3840
*
3941
*/
4042

41-
using('Base', function(Base) {
43+
define(['Base'], function(Base) {
4244

4345
Base.addFeature({
4446

src/features/standard/notify-path.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
* @class data feature: path notification
5959
*/
6060

61-
using(['Base', 'Annotations'], function(Base, Annotations) {
61+
define(['Base', 'Annotations'], function(Base, Annotations) {
6262

6363
Base.addFeature({
6464
/**

src/features/standard/styling.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<link rel="import" href="../../lib/shadow-settings.html">
1313
<script>
1414

15-
using(['Base', 'StyleTransformer', 'StyleUtil', 'ShadowSettings', 'Annotations'],
15+
define(['Base', 'StyleTransformer', 'StyleUtil', 'ShadowSettings', 'Annotations'],
1616
function(Base, transformer, styleUtil, settings, Annotations) {
1717

1818
var prepTemplate = Base._prepTemplate;

src/features/standard/utils.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<script>
1515

16-
using(['Base', 'Async', 'Debounce'], function(Base, Async, Debounce) {
16+
define(['Base', 'Async', 'Debounce'], function(Base, Async, Debounce) {
1717

1818
Base.addFeature({
1919

src/lib/annotations/annotations.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
* @class Template feature
6363
*/
6464

65-
modulate('Annotations', function() {
65+
define('Annotations', function() {
6666

6767
// null-array (shared empty array to avoid null-checks)
6868
var nar = [];

src/lib/annotations/demo/app-chrome.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
<script>
3838

39-
using('Annotations', function(Annotations) {
39+
define('Annotations', function(Annotations) {
4040

4141
var template = document.querySelector('template');
4242
var list = Annotations.parseAnnotations(template);

src/lib/array-observe.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<script>
1313

14-
modulate('ArrayObserve', 'Debounce', function(Debounce) {
14+
define('ArrayObserve', ['Debounce'], function(Debounce) {
1515

1616
var callbacks = new WeakMap();
1717

src/lib/array-splice.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
99
-->
1010
<script>
11-
modulate('ArraySplice', function() {
12-
11+
define('ArraySplice', function() {
12+
1313
function newSplice(index, removed, addedCount) {
1414
return {
1515
index: index,

src/lib/async.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
-->
1010
<script>
1111

12-
modulate('Async', function() {
13-
12+
define('Async', function() {
13+
1414
var currVal = 0;
1515
var lastVal = 0;
1616
var callbacks = [];

src/lib/base.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
-->
1010
<script>
1111

12-
modulate('Base', function() {
12+
define('Base', function() {
1313

1414
var Base = {
1515

src/lib/bind/bind-annotations.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<script>
1212

13-
modulate('bind-annotations', ['bind'], function(Bind) {
13+
define('bind-annotations', ['bind'], function(Bind) {
1414

1515
/*
1616
* Parses the annotations list created by `annotations` features to perform

src/lib/bind/bind-effects.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
-->
1010
<script>
1111

12-
using(['Annotations', 'bind'], function(Annotations, Bind) {
12+
define(['Annotations', 'bind'], function(Annotations, Bind) {
1313

1414
Bind.addComputedPropertyEffect = function(model, name, expression) {
1515
var index = expression.indexOf('(');

src/lib/bind/bind.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
-->
1010
<script>
1111

12-
modulate('bind', function() {
12+
define('bind', function() {
1313

1414
var Bind = {
1515

src/lib/bind/demo/src/annotations-bind-demo.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
// TODO(sjmiles): should 'bind-annotations' blend the other two modules
2020
// somehow so we don't need to include all three here?
21-
using(['Annotations', 'bind', 'bind-annotations'],
21+
define(['Annotations', 'bind', 'bind-annotations'],
2222

2323
function(Annotations, Bind, BindAnnotations) {
2424

src/lib/bind/demo/src/bind-demo.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<script>
66

7-
using(['bind'], function(Bind) {
7+
define(['bind'], function(Bind) {
88

99
var out = document.querySelector('#bd');
1010
out.innerHTML += '<hr><h3>bind demo</h3><hr>';

src/lib/collection.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<script>
1515

16-
modulate('Collection', ['Base', 'ArrayObserve', 'Debounce'], function(Base, ArrayObserve, Debounce) {
16+
define('Collection', ['Base', 'ArrayObserve', 'Debounce'], function(Base, ArrayObserve, Debounce) {
1717

1818
var collections = new WeakMap();
1919

src/lib/css-parse.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Extremely simple css parser. Intended to be not more than what we need
55
and definitely not necessarly correct =).
66
*/
7-
modulate('CssParse', function() {
7+
define('CssParse', function() {
88

99
// given a string of css, return a simple rule tree
1010
function parse(text) {

src/lib/debounce.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
-->
1010
<script>
1111

12-
modulate('Debounce', 'Async', function(Async) {
13-
12+
define('Debounce', ['Async'], function(Async) {
13+
1414
// usage
1515

1616
// invoke cb.call(this) in 100ms, unless the job is re-registered,

0 commit comments

Comments
 (0)