Skip to content

Commit

Permalink
use class to follow React ESLint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
scriptPilot committed Mar 3, 2024
1 parent d31c84a commit 8f4d9b9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Based on the installation path above.
import Dexie from 'dexie'
// Import the sync hook
import useSync from 'dexie-mysql-sync'
import Sync from 'dexie-mysql-sync'
// Setup the local database
// Adding $created and $deleted as index allows to query on these fields
Expand All @@ -84,7 +84,7 @@ Based on the installation path above.
})
// Start the synchronization
const sync = useSync()
const sync = new Sync()
sync.add(db.tasks, 'tasks')
// Export the database and sync objects
Expand Down
4 changes: 2 additions & 2 deletions demo-app/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Dexie from 'dexie'
import { useLiveQuery } from 'dexie-react-hooks'

// Import the sync hook
import usesSync from 'dexie-mysql-sync'
import Sync from 'dexie-mysql-sync'

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

// Start the synchronization
const sync = usesSync()
const sync = new Sync()
sync.add(db.tasks, 'tasks')
sync.add(db.files, 'files')

Expand Down
33 changes: 16 additions & 17 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@ import user from './user'
import password from './password'
import logout from './logout'

function useSync(endpoint = '/api.php') {
const localStorageUserKey = `dexie-mysql-sync > user > ${endpoint}`
return {
endpoint,
localStorageUserKey,
api: useAPI(endpoint),
debug,
syncs: [],
add,
reset,
emptyTable,
register,
login,
user,
password,
logout
export class Sync {
constructor(endpoint = '/api.php') {
this.endpoint = endpoint
this.localStorageUserKey = `dexie-mysql-sync > user > ${endpoint}`
this.syncs = []
this.api = useAPI(this.endpoint)
this.debug = debug
this.add = add
this.reset = reset
this.emptyTable = emptyTable
this.register = register
this.login = login
this.user = user
this.password = password
this.logout = logout
}
}

export default useSync
export default Sync

0 comments on commit 8f4d9b9

Please sign in to comment.