Skip to content
This repository was archived by the owner on Jun 5, 2018. It is now read-only.

Commit 3d57a3e

Browse files
committed
fix bug: 未能从缓存加载文件
1 parent 3397dec commit 3d57a3e

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@
6969
</details>
7070
</dl>
7171
</template>
72-
<script src='js/script.js'></script>
72+
<script src='js/script.js?_=1526892615177'></script>
7373
</body>
7474
</html>

js/script.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
get(path) {
3838
path = `${this.owner}/${this.repo}/${path}`;
3939
let data = getCache(path);
40-
if (data) return Promise.resolve(data);
40+
if (data) return Promise.resolve(data).then(dispatch);
4141

4242
return fetch(`${api}/${path}`).then(
4343
(resp)=>this.normalize(resp)
@@ -46,7 +46,7 @@
4646
new CustomEvent('gohub-catch', {detail: data })
4747
);
4848
return data;
49-
});
49+
}).then(dispatch);
5050
}
5151

5252
normalize(resp) {
@@ -67,26 +67,30 @@
6767
slice(1).toLowerCase(),
6868
text = Base64.decode(json.content),
6969
content = ext === 'json' &&
70-
JSON.parse(text) || text,
71-
data = storeCache(
72-
url, {
73-
owner, repo,
74-
name: json.name,
75-
url: json.html_url,
76-
sha: json.sha,
77-
path,
78-
ext,
79-
content,
80-
}
81-
);
82-
document.dispatchEvent(
83-
new CustomEvent('gohub-got', {detail: data })
70+
JSON.parse(text) || text;
71+
72+
return storeCache(
73+
url, {
74+
owner, repo,
75+
name: json.name,
76+
url: json.html_url,
77+
sha: json.sha,
78+
path,
79+
ext,
80+
content,
81+
}
8482
);
85-
return data;
8683
});
8784
}
8885
}
8986

87+
function dispatch(data) {
88+
document.dispatchEvent(
89+
new CustomEvent('gohub-got', {detail: data })
90+
);
91+
return data;
92+
}
93+
9094
global.gohub = function (owner, repo) {
9195
if (!owner) return gohub.prototype;
9296
return new gohub(owner, repo);

0 commit comments

Comments
 (0)