-
Notifications
You must be signed in to change notification settings - Fork 4
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shocked Specification Discussion #19
Comments
@karkipy Test the specification from |
useNetInfo Implementation for react-native function useNetStatus() {
const [online, setOnline] = useState(false);
const handler = useCallback((info) => {
setOnline(info.type !== 'none');
}, [setOnline]);
useEffect(() => {
NetInfo.getConnectionInfo().then(handler);
NetInfo.addEventListener('connectionChange', handler);
return () => {
NetInfo.removeEventListener('connectionChange', handler);
};
});
return online;
} |
Defining api on the client sideCase 1: The api doesn't support offline execution const myRemoteApi = null; Case 2: The api supports offline execution const offlineDB = new SomeXYZOfflineDatabase();
const myRemoteApi = (session) => {
const sync = offlineDB.registerSync(MY_REMOTE_API_ID, (token) => {
const payload = offlineDB.retrievePayload(token);
return session.myRemoteApi(payload);
});
return async (payload) => {
// Add sync token for synchronization later
await sync(someTokenFromPayload);
// Perform offline operation
return offlineDB.consumeApiOffline(payload);
};
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Properties:
Connection Props
Starts a new connection (when any one changes). No connection is made when either of them is falsy.
url: null | string
Remote endpoint (Ex: http://example.com/your-app/params)
ident: null | {}
User identification token. Ex:
{ type: 'fb', token: 'asdfsfkljsdfjasldf' }
network: boolean
Network online status
clearIdent: () => void
A callback invoked when the server doesn't identify the
ident
value sent over for identificationCommunication Props
api: { [string]: API }
API structure available for execution on the shocked instance.
context: any
Client context to match with server
Synchronization Props
dispatch: (state, action) => void
The dispatch method to synchronize server state with client. This should be the
dispatch
method of your redux or redux compatible stores.sync: () => Promise<void>
A synchronization function that is invoked as soon as the connection goes online. Use this opportunity to synchronize all offline data with the server
Configuration Props
retryInterval: number
default: 1000Number of milliseconds before which reconnection attempts are not made. Reconnection attempts are made whenever the connection is terminated, unless the connection has been rejected by the server (4001).
Example
The text was updated successfully, but these errors were encountered: