Skip to content

Commit 8f4d9b9

Browse files
committed
use class to follow React ESLint rules
1 parent d31c84a commit 8f4d9b9

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Based on the installation path above.
7474
import Dexie from 'dexie'
7575
7676
// Import the sync hook
77-
import useSync from 'dexie-mysql-sync'
77+
import Sync from 'dexie-mysql-sync'
7878
7979
// Setup the local database
8080
// Adding $created and $deleted as index allows to query on these fields
@@ -84,7 +84,7 @@ Based on the installation path above.
8484
})
8585
8686
// Start the synchronization
87-
const sync = useSync()
87+
const sync = new Sync()
8888
sync.add(db.tasks, 'tasks')
8989
9090
// Export the database and sync objects

demo-app/src/store.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Dexie from 'dexie'
55
import { useLiveQuery } from 'dexie-react-hooks'
66

77
// Import the sync hook
8-
import usesSync from 'dexie-mysql-sync'
8+
import Sync from 'dexie-mysql-sync'
99

1010
// Setup the local database
1111
// Adding $created and $deleted as index allows to query on these fields
@@ -16,7 +16,7 @@ db.version(1).stores({
1616
})
1717

1818
// Start the synchronization
19-
const sync = usesSync()
19+
const sync = new Sync()
2020
sync.add(db.tasks, 'tasks')
2121
sync.add(db.files, 'files')
2222

lib/index.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,22 @@ import user from './user'
1010
import password from './password'
1111
import logout from './logout'
1212

13-
function useSync(endpoint = '/api.php') {
14-
const localStorageUserKey = `dexie-mysql-sync > user > ${endpoint}`
15-
return {
16-
endpoint,
17-
localStorageUserKey,
18-
api: useAPI(endpoint),
19-
debug,
20-
syncs: [],
21-
add,
22-
reset,
23-
emptyTable,
24-
register,
25-
login,
26-
user,
27-
password,
28-
logout
13+
export class Sync {
14+
constructor(endpoint = '/api.php') {
15+
this.endpoint = endpoint
16+
this.localStorageUserKey = `dexie-mysql-sync > user > ${endpoint}`
17+
this.syncs = []
18+
this.api = useAPI(this.endpoint)
19+
this.debug = debug
20+
this.add = add
21+
this.reset = reset
22+
this.emptyTable = emptyTable
23+
this.register = register
24+
this.login = login
25+
this.user = user
26+
this.password = password
27+
this.logout = logout
2928
}
3029
}
3130

32-
export default useSync
31+
export default Sync

0 commit comments

Comments
 (0)