GithubHelp home page GithubHelp logo

raphaelpor / sync-storage Goto Github PK

View Code? Open in Web Editor NEW
82.0 4.0 31.0 2.05 MB

Synchronous storage for React Native.

License: Other

JavaScript 2.60% Python 0.11% Java 0.48% Objective-C 0.80% CSS 0.99% HTML 95.02%

sync-storage's Introduction

SyncStorage

Synchronous storage for React Native AsyncStorage.

Build Status codecov npm version license

Get Started

Installation

yarn add sync-storage
# or
# npm i --save sync-storage

Usage

import SyncStorage from 'sync-storage';

SyncStorage.set('foo', 'bar');

const result = SyncStorage.get('foo');
console.log(result); // 'bar'

Methods Available

init()

Init prepares the SyncStorage to work synchronously, by getting all values for all keys previously saved on RN AsyncStorage. See the example:

const data = await SyncStorage.init();
console.log('AsyncStorage is ready!', data);

get(key: string)

Returns the value of key.

SyncStorage.get('foo'); // 'bar'

set(key: string, value: Any type)

It saves the value on memory and on the AsyncStorage.

SyncStorage.set('foo', 'bar');
SyncStorage.get('foo'); // 'bar'

It also returns a Promise for post verification.

SyncStorage.set('foo', 'bar')
  .then(() => {
    SyncStorage.get('foo'); // 'bar'
  })
  .catch(error => {
    console.log(error);
  });

remove(key: string)

It removes the value from the memory and from the AsyncStorage.

SyncStorage.remove('foo');

It also returns a Promise for post verification.

SyncStorage.remove('foo')
  .then(() => {
    SyncStorage.get('foo'); // undefined
  })
  .catch(error => {
    console.log(error);
  });

getAllKeys()

returns an array from all the keys.

SyncStorage.set('foo', 'bar');
SyncStorage.set('boo', 'baz');
console.log(SyncStorage.getAllKeys()) // ['foo', 'boo']

sync-storage's People

Contributors

billnbell avatar dependabot[bot] avatar iamsoorena avatar olfek avatar raphaelpor avatar redoh 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  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  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  avatar

sync-storage's Issues

Great Job!

No issue here, just wanted to give a shout out because I spent over 12 hours trying to come up with a valid solution to Sync. localStorage before I came across this gem.

error after installing sync-storage

SyntaxError: C:\Users\profd\Desktop\Projects\my_library\node_modules\sync-storage\src\index.js: Missing semicolon. (5:4)

i'm getting this error after i nstall syncStorage using npm and try to import syncstorage

> type KeyType = string;

ERROR
22:05
./node_modules/sync-storage/src/index.js 5:5
Module parse failed: Unexpected token (5:5)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| import handleError from './helpers/handleError';
| 
> type KeyType = string;
| 
| class SyncStorage {

Parse Error for type

With expo clean install, i'm getting this. Any idea how to clear this?

/Users/myname/Work/ReactNative/testapp/node_modules/sync-storage/src/index.js 5:5
Module parse failed: Unexpected token (5:5)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| import handleError from './helpers/handleError';
| 
> type KeyType = string;
| 
| class SyncStorage {

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.