This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CDNJS - 25.6KB | |
curl 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js' --silent -H 'Accept-Encoding: gzip,deflate' --write-out '%{size_download}\n' --output /dev/null | |
25594 | |
# JSDELIVR - 24.2KB | |
curl 'https://cdn.jsdelivr.net/lodash/4.17.4/lodash.min.js' --silent -H 'Accept-Encoding: gzip,deflate' --write-out '%{size_download}\n' --output /dev/null | |
24161 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_inventory_item(request): | |
body_unicode = request.body.decode('utf-8') | |
body = json.loads(body_unicode) | |
idempotent_id = body.get('idempotent_id') | |
item = InventoryModel.objects.get(idempotent_id=idempotent_id) | |
if item: | |
return JsonResponse(item) # Will include the backend primary key ID | |
else: | |
InventoryModel.objects.create( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
const Loading = () => (<div>Loading...</div>) | |
const App = () => { | |
return ( | |
<Provider store={store}> | |
<PersistGate loading={<Loading />} persistor={persistor}> | |
<RootComponent /> | |
</PersistGate> | |
</Provider> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import storage from 'redux-persist/lib/storage' // defaults to localStorage for web and AsyncStorage for react-native | |
const reduxPersistConfig = { | |
key: 'root', | |
storage: storage, | |
blacklist: ['sensitive-data', 'ephemeral-state'] | |
// Or: | |
whitelist: ['list-of-foos', 'list-of-bars'] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const reduxOfflineConfig = { | |
..., | |
detectNetwork: callback => { | |
setInterval(async () => { | |
try { | |
await fetch('yourbackend.com/ping', { method: 'HEAD' }) | |
callback({ | |
online: true | |
}) | |
} catch(e) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const followUser = userId => ({ | |
type: 'FOLLOW_USER_REQUEST', | |
payload: { userId }, | |
meta: { | |
offline: { | |
// the network action to execute: | |
effect: { url: '/api/follow', method: 'POST', body: JSON.stringify({ userId }) }, | |
// action to dispatch when effect succeeds: | |
commit: { type: 'FOLLOW_USER_COMMIT', meta: { userId } }, | |
// action to dispatch if network action fails permanently: |
OlderNewer