Git Product home page Git Product logo

redux-persist-expo-filesystem's People

Contributors

t73liu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

redux-persist-expo-filesystem's Issues

Not working with Expo SDK 37 and v6 redux-persist

I wasn't able to get this work with v6 and redux-persist. Not sure of there is a bug in redux-persist or if this component needs an update to work with v6

"redux-persist failed to create sync storage, failing back to noop storage" when I try to pass this component here as storage.

Works perfectly fine with v5

License

Hi, would be nice if this included a license so that credit could be properly given.

Missing Promise Resolution in setItem Callback

Missing Promise Resolution in setItem Callback

Description

setItem callback in the redux persist is expected to return a promise that resolves upon successful writing. However, the code below only waits for getInforAsync to resolve and does not handle the resolution of the setItem promise after a successful write operation.

setItem(key, value) {
        const folderPath = generateFolderPath();
        return FileSystem.getInfoAsync(folderPath)
            .then(info => {
                const filePath = generateFilePath(key);
                if (info.exists) {
                    writeFile(filePath, value);
                } else {
                    FileSystem.makeDirectoryAsync(folderPath, {intermediates: true})
                        .then(() => writeFile(filePath, value));
                }
            });
    }
function writeFile(path, value) {
    FileSystem.writeAsStringAsync(path, value);
}

The correct version should be as follows:

  setItem(key, value) {
    const folderPath = generateFolderPath();
    return FileSystem.getInfoAsync(folderPath)
            .then(async info => {
                const filePath = generateFilePath(key);
                if (info.exists) {
                    await writeFile(filePath, value);
                } else {
                    await FileSystem.makeDirectoryAsync(folderPath, {intermediates: true})
                        .then(() => writeFile(filePath, value));
                }
            });
  }

async function writeFile(path, value) {
  await FileSystem.writeAsStringAsync(path, value);
}

Replicated a similar situation using a straightforward examplePromise.

Expected Behavior: The system should wait for the resolution of both promises, and the execution of console.log("after execution") should occur at the end.

Wrong Version (equivalent to the current version of setItem)

// Create a function that returns a Promise
function examplePromise(value) {
  return new Promise((resolve, reject) => {
    // Simulate a delay of 20 seconds using setTimeout
    setTimeout(() => {
      // Check the value and resolve or reject the Promise accordingly after the delay
      if (value) {
        // If the value exists, resolve the Promise
        console.log('execution: examplePromise: ' + value)
        resolve('Promise resolved successfully with: ' + value);
      } else {
        // If the value doesn't exist, reject the Promise
        reject('Promise rejected: No value provided');
      }
    }, 20000); // 20 seconds delay (20000 milliseconds)
  });
}


const setItem = ()=>{
    return examplePromise(1).then((res)=>{
            examplePromise(2)
   });
   
}
const parent =async()=>{
    console.log("before execution")
    await setItem()
    console.log("after execution")
}
parent()

Output

before execution
execution: examplePromise: 1
after execution
execution: examplePromise: 2

Correct Version (equivalent to the improved setItem version)

// Create a function that returns a Promise
function examplePromise(value) {
  return new Promise((resolve, reject) => {
    // Simulate a delay of 20 seconds using setTimeout
    setTimeout(() => {
      // Check the value and resolve or reject the Promise accordingly after the delay
      if (value) {
        // If the value exists, resolve the Promise
        console.log('execution: examplePromise: ' + value)
        resolve('Promise resolved successfully with: ' + value);
      } else {
        // If the value doesn't exist, reject the Promise
        reject('Promise rejected: No value provided');
      }
    }, 20000); // 20 seconds delay (20000 milliseconds)
  });
}


const setItem = ()=>{
    return examplePromise(1).then(async(res)=>{
           await  examplePromise(2)
   });
   
}
const parent =async()=>{
    console.log("before execution")
    await setItem()
    console.log("after execution")
}
parent()

Output

before execution
execution: examplePromise: 1
execution: examplePromise: 2
after execution

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.