Skip to content

Commit

Permalink
slow down imports because of #4
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrZatacke committed Jul 8, 2020
1 parent e219b22 commit 4e954f3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/javascript/app/store/middlewares/plainText.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const plainText = (store) => {
type: 'SET_ALL_LINES',
payload: images.shift(),
});
}, 50);
}, 150);

store.dispatch({
type: 'IMPORT_QUEUE_SIZE',
Expand Down
9 changes: 9 additions & 0 deletions src/javascript/tools/delayPromise/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const delayPromise = (delay) => (value) => (
new Promise(((resolve) => {
window.setTimeout(() => {
resolve(value);
}, delay);
}))
);

export default delayPromise;
27 changes: 13 additions & 14 deletions src/javascript/tools/remotestorage/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,18 @@ const GbPrinterWeb = {
});
},

putRawImage: (rawImage, hash) => {
console.log('putRaw', rawImage);
return (
client.storeObject('rawImage', `rawImages/${hash}`, rawImage)
);
},
putRawImage: (rawImage, hash) => (
client.storeObject('rawImage', `rawImages/${hash}`, rawImage)
),

getRawImage: (hash) => (
client.getObject(`rawImages/${hash}`)
),


deleteRawImage: (hash) => {
console.log('deleteRawImage', hash);
return client.remove(`rawImages/${hash}`);
},
deleteRawImage: (hash) => (
client.remove(`rawImages/${hash}`)
),

putImage: (image) => {
const savedImage = { ...image };
Expand Down Expand Up @@ -97,10 +93,13 @@ const GbPrinterWeb = {

getImages: () => (
client.getAll('images/')
.then((images) => {
console.log(Object.values(images));
return Object.values(images);
})
.then((images) => (
Object.values(images)
))
// .then((images) => {
// console.log(Object.values(images));
// return Object.values(images);
// })
.then((images) => (
images.sort(({ timestamp: tsa }, { timestamp: tsb }) => {
if (tsa < tsb) {
Expand Down
2 changes: 2 additions & 0 deletions src/javascript/tools/storage/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dummyImage from './dummyImage';
import applyFrame from '../applyFrame';
import getRemoteStorage from '../remotestorage';
import delayPromise from '../delayPromise';

const remoteStorage = getRemoteStorage();

Expand All @@ -14,6 +15,7 @@ const save = (lineBuffer) => (

const dataHash = hash(imageData);
return remoteStorage.gbPrinterWeb.putRawImage(imageData, dataHash)
.then(delayPromise(150))
.then(() => dataHash);
})
);
Expand Down

0 comments on commit 4e954f3

Please sign in to comment.