@@ -71,19 +71,8 @@ export function saveUser (repoName, user) {
7171export function init ( ) {
7272 // set repositories info
7373 getRepositories ( )
74-
75- data = getData ( )
76-
74+ data = jetpack . read ( getLocalPath ( ) , 'json' )
7775 if ( data == null ) {
78- // for 0.4.1 -> 0.4.2
79- if ( localStorage . getItem ( 'local' ) != null ) {
80- data = JSON . parse ( localStorage . getItem ( 'local' ) )
81- jetpack . write ( getLocalPath ( ) , data )
82- localStorage . removeItem ( 'local' )
83- console . log ( 'update 0.4.1 => 0.4.2' )
84- return
85- }
86-
8776 let defaultFolder = {
8877 name : 'default' ,
8978 key : keygen ( )
@@ -108,14 +97,11 @@ export function init () {
10897 }
10998}
11099
111- export function getData ( ) {
112- if ( data == null ) {
100+ export function getData ( forceRead ) {
101+ if ( forceRead ) {
113102 try {
114103 data = jetpack . read ( getLocalPath ( ) , 'json' )
115-
116- } catch ( e ) {
117- return null
118- }
104+ } catch ( e ) { }
119105 }
120106 return data
121107}
@@ -140,7 +126,7 @@ function queueSave () {
140126 if ( timer ) {
141127 clearTimeout ( timer )
142128 }
143- timer = setTimeout ( saveData , 3000 )
129+ timer = setTimeout ( saveData , 500 )
144130 } else {
145131 saveAgain = true
146132 }
@@ -160,21 +146,11 @@ export function setFolders (folders) {
160146 queueSave ( )
161147}
162148
163- function isFinderCalled ( ) {
164- var argv = process . argv . slice ( 1 )
165- return argv . some ( arg => arg . match ( / - - f i n d e r / ) )
149+ export default {
150+ getUser,
151+ saveUser,
152+ init,
153+ getData,
154+ setArticles,
155+ setFolders
166156}
167-
168- export default ( function ( ) {
169- if ( ! isFinderCalled ( ) ) {
170- init ( )
171- }
172- return {
173- getUser,
174- saveUser,
175- init,
176- getData,
177- setArticles,
178- setFolders
179- }
180- } ) ( )
0 commit comments