Skip to content

Commit

Permalink
* Array comprehension is gone from ES6; adjust accordingly.
Browse files Browse the repository at this point in the history
  • Loading branch information
audreyt committed Oct 8, 2014
1 parent 293058e commit 897a781
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 133 deletions.
2 changes: 1 addition & 1 deletion spreadsheet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ If you'd like to use Chrome, type `make run` or `node extra/static-here.js` and

To build from source, first install [NodeJS](http://www.nodejs.org/) 0.10 or later, and run `make` (only tested on Linux/OSX at the moment).

JS source code (`main.js` and `worker.js`) are written in ECMAScript 6 (aka _ES.next_, aka _Harmony_), specifically the subset marked with [TC39 Consensus](https://developer.mozilla.org/en-US/docs/Web/JavaScript/ECMAScript_6_support_in_Mozilla) as of February 2014.
JS source code (`main.js` and `worker.js`) are written in ECMAScript 6 (aka _Harmony_), specifically the [feature-frozen draft](https://developer.mozilla.org/en-US/docs/Web/JavaScript/ECMAScript_6_support_in_Mozilla) as of August 2014.

For backward compatibility with ECMAScript 5 browsers, we use [Traceur](https://github.com/google/traceur-compiler) to compile source files into the `es5/` directory.

Expand Down
51 changes: 17 additions & 34 deletions spreadsheet/es5/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

134 changes: 43 additions & 91 deletions spreadsheet/es5/worker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions spreadsheet/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
angular.module('500lines', []).controller('Spreadsheet', function ($scope, $timeout) {
// Begin of $scope properties; start with the column/row labels
$scope.Cols = [ for (col of range( 'A', 'H' )) col ];
$scope.Rows = [ for (row of range( 1, 20 )) row ];
$scope.Cols = [], $scope.Rows = [];
for (col of range( 'A', 'H' )) { $scope.Cols.push(col); }
for (row of range( 1, 20 )) { $scope.Rows.push(row); }

function* range(cur, end) { while (cur <= end) { yield cur;
// If it’s a number, increase it by one; otherwise move to next letter
Expand Down
10 changes: 5 additions & 5 deletions spreadsheet/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ self.onmessage = ({data})=>{

for (const coord in sheet) {
// Four variable names pointing to the same coordinate: A1, a1, $A1, $a1
for (const name of [ for (p of [ '', '$' ])
for (c of [ coord, coord.toLowerCase() ])
p+c ]) {
[ '', '$' ].map( p => [ coord, coord.toLowerCase() ].map(c => {
const name = p+c;

// Worker is reused across computations, so only define each variable once
if ((Object.getOwnPropertyDescriptor( self, name ) || {}).get) { continue; }
if ((Object.getOwnPropertyDescriptor( self, name ) || {}).get) { return; }

// Define self['A1'], which is the same thing as the global variable A1
Object.defineProperty( self, name, { get() {
Expand Down Expand Up @@ -37,7 +37,7 @@ self.onmessage = ({data})=>{
switch (typeof vals[coord]) { case 'function': case 'object': vals[coord]+=''; }
return vals[coord];
} } );
}
}));
}

// For each coordinate in the sheet, call the property getter defined above
Expand Down

0 comments on commit 897a781

Please sign in to comment.