forked from algorithm-visualizer/algorithm-visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_scratch_paper.js
More file actions
48 lines (36 loc) · 1.16 KB
/
load_scratch_paper.js
File metadata and controls
48 lines (36 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
const RSVP = require('rsvp');
const app = require('../app');
const {
getFileDir
} = require('../utils');
const getJSON = require('./ajax/get_json');
const loadAlgorithm = require('./load_algorithm');
const extractGistCode = (files, name) => files[`${name}.js`].content;
module.exports = (gistID) => {
return new RSVP.Promise((resolve, reject) => {
app.setLoadedScratch(gistID);
getJSON(`https://api.github.com/gists/${gistID}`).then(({
files
}) => {
const category = 'scratch';
const algorithm = gistID;
loadAlgorithm(category, algorithm).then((data) => {
const algoData = extractGistCode(files, 'data');
const algoCode = extractGistCode(files, 'code');
// update scratch paper algo code with the loaded gist code
const dir = getFileDir(category, algorithm, 'scratch_paper');
app.updateCachedFile(dir, {
data: algoData,
code: algoCode,
'CREDIT.md': 'Shared by an anonymous user from http://parkjs814.github.io/AlgorithmVisualizer'
});
resolve({
category,
algorithm,
data
});
});
});
});
};