Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make scope-chains-closures translatable #27

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bin/scope-chains-closures
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('../scope-chains-closures.js').execute(process.argv.slice(2));
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Closures

Closures are an important part of the Javascript language. They are what enables
the callback-last programming most prominent in node, and provide an excellent
mechanism for handling the asynchronous nature of most Javascript tasks.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Garbage Collection

Memory in Javascript is managed automatically by the runtime. The runtime
decides when/if to release any allocated memory. This decision process is called
_Garbage Collection_.
Expand Down Expand Up @@ -48,12 +46,13 @@ In this challenge, you will be required to use Chrome DevTools for detecting
Garbage Collection events. Follow these steps to get a feel for what happens
when Chrome performs its Mark & Sweep algorithm:

```
1) Fire up a new tab in Chrome
2) Open the DevTools > Timeline tab
3) Ensure the settings are like so: `http://i.imgur.com/RMovIw4.png`
a) Frames View is unselected (allows seeing memory graphs)
b) Flame Chart View is selected (allows seeing where execution time is spent)
c) Only "Memory" is selected from the options
a) Frames View is unselected (allows seeing memory graphs)
b) Flame Chart View is selected (allows seeing where execution time is spent)
c) Only "Memory" is selected from the options
4) Click the solid gray record button to begin capturing data
5) Visit `http://www.stackoverflow.com` (or your favourite website)
6) Click the now-red record button to stop capturing data
Expand All @@ -64,6 +63,7 @@ when Chrome performs its Mark & Sweep algorithm:
10) Now look for the yellow event called "GC Event": `http://i.imgur.com/3ieSxIZ.png`
11) Clicking this event will reveal information about total memory garbage
collected, and how long it took.
```

One particularly interesting thing of note here is the length of time Garbage
Collection can take: Often well beyond the 16ms maximum required to keep it
Expand Down
1 change: 0 additions & 1 deletion exercises/garbage-collection/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var problem = require('../../problem');

module.exports = {
title: 'Garbage Collection',
problem: problem(__dirname, function (args, t) {
t.end();
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Global Scope & Shadowing

## Global Scope

Understanding where Scope Chains end is an important part of scoping. All
Expand Down
1 change: 0 additions & 1 deletion exercises/global-scope-and-shadowing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var fs = require('fs'),
asciiScope = require('../../util/ascii-scope');

module.exports = {
title: 'Global Scope & Shadowing',
problem: problem(__dirname, function (args, t) {

var file = path.resolve(args[0]);
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Scope Chains

## Nesting

Scopes can be nested. Both Lexical and Block scopes can contain other scopes:
Expand Down
1 change: 0 additions & 1 deletion exercises/scope-chains/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var fs = require('fs'),
asciiScope = require('../../util/ascii-scope');

module.exports = {
title: 'Scope Chains',
problem: problem(__dirname, function (args, t) {

var file = path.resolve(args[0]);
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ them all along without realising.

----

# Scopes
## __{currentExercise.name}__ (_{progress.state_resolved}_)

The main type of scope in Javascript is Lexical Scoping. Present in the language
from the very beginning, this is the scope created within a function, and the
Expand Down Expand Up @@ -64,3 +64,4 @@ solution.
* [1]: There are also 4 other scopes in the language: Global, `with`, `catch`,
and `eval`. These tend not to be used much, so we will ignore them.
* [2]: This workshop will concentrate only on Lexical Scoping.

File renamed without changes.
1 change: 0 additions & 1 deletion exercises/scopes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var fs = require('fs'),
asciiScope = require('../../util/ascii-scope');

module.exports = {
title: 'Scopes',
problem: problem(__dirname, function (args, t) {

var file = path.resolve(args[0]);
Expand Down
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
"name": "scope-chains-closures",
"version": "1.0.4",
"description": "Javascript Scope Chains And Closures Workshop",
"main": "runner.js",
"main": "scope-chains-closures.js",
"bin": {
"scope-chains-closures": "runner.js",
"sccjs": "runner.js"
"scope-chains-closures": "bin/scope-chains-closures",
"sccjs": "bin/scope-chains-closures"
},
"engineStrict": true,
"preferGlobal": true,
"repository": "jesstelford/scope-chains-closures",
"repository": {
"type": "git",
"url": "https://github.com/jesstelford/scope-chains-closures.git"
},
"bugs": "https://github.com/jesstelford/scope-chains-closures/issues",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand All @@ -27,11 +30,11 @@
"author": "Jess Telford <[email protected]> (http://jes.st)",
"license": "MIT",
"dependencies": {
"adventure": "^2.10.0",
"adventure-verify": "^2.2.0",
"babel-core": "^5.4.3",
"escope": "^1.0.3",
"estraverse": "^4.1.0",
"msee": "^0.1.1"
"msee": "^0.1.1",
"workshopper-adventure": "^4.7.0"
}
}
17 changes: 8 additions & 9 deletions problem.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
var msee = require('msee'),
path = require('path'),
var path = require('path'),
verify = require('adventure-verify');

module.exports = function(dir, testCorrect) {

var problem = {
init: function (exercise) {
['problem', 'solution', 'pass', 'fail'].forEach(function(type) {
problem[type] = {
file: path.join(dir, exercise.i18n.lang(), type + '.md')
}
});
},
verify: verify({ modeReset: true }, testCorrect)
};

['problem', 'solution', 'pass', 'fail'].forEach(function(type) {
problem[type] = msee.parseFile(
dir + '/' + type + '.md',
{paragraphEnd: '\n\n'}
);
});

return problem;
};
26 changes: 0 additions & 26 deletions runner.js

This file was deleted.

30 changes: 30 additions & 0 deletions scope-chains-closures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

var packageJson = require('./package.json'),
adventure = require('workshopper-adventure/adventure');

var shop = adventure({
name: packageJson.name,
appDir: __dirname,
languages: ['en'],
header: require('workshopper-adventure/default/header'),
footer: [
{text: '---', type: 'md'},
require('workshopper-adventure/default/footer')
]
});

[
'Scopes',
'Scope Chains',
'Global Scope & Shadowing',
'Closures',
'Garbage Collection'
].forEach(function(title, index) {
shop.add(title, function() {
var folder = title.replace(/\s/ig, '-').replace(/\&/ig, 'and')
return require('./exercises/' + folder).problem
});
})

module.exports = shop