1.1.1 • Published 7 years ago
mobx-stores v1.1.1
MobX stores for ReactJS applications.
Requirements
For using these stores you need to have a ReactJS application with MobX package installed. All methods and properties will re-render your components if called in an @observable
class.
Installation
> npm i mobx-stores
Stores
- DeviceStore
- LocalStore (>= 1.1.0)
- SessionStore
1. DeviceStore
DeviceStore is made for get information about user device: mobile or desktop.
NB: Create a new instance in order to use it as soon as your application start.
import { DeviceStore } from 'mobx-stores';
export const deviceStore = new DeviceStore();
Property | Return value | Description |
---|---|---|
isMobile | boolean | Returns true if the device is mobile. |
isDesktop | boolean | Returns true if the device is desktop. |
isPortrait | boolean | Returns true if the device is in portrait mode. |
isLandscape | boolean | Returns true if the device is in landscape mode. |
isMobilePortrait | boolean | Returns true if the device is mobile and in portrait mode. |
isMobileLandscape | boolean | Returns true if the device is mobile and in landscape mode. |
Usage example:
if (deviceStore.isMobile) {
// do some stuff..
}
2. LocalStore
LocalStore is made for set and get variables in the browser's local storage.
NB: Create a new instance in order to use it as soon as your application start.
import { LocalStore } from 'mobx-stores';
export const localStore = new LocalStore();
Action | Return value | Arguments | Description |
---|---|---|---|
set | void | key (string), value(any) | Set a pair { key: value }. |
get | string | key (string) | Returns the value of the corresponding key. |
Usage example:
localStore.set('username', 'tillo-dev');
console.log(localStore.get('username'));
3. SessionStore
SessionStore is made for set and get variables in the browser's session storage.
NB: Create a new instance in order to use it as soon as your application start.
import { SessionStore } from 'mobx-stores';
export const sessionStore = new SessionStore();
Action | Return value | Arguments | Description |
---|---|---|---|
set | void | key (string), value(any) | Set a pair { key: value }. |
get | string | key (string) | Returns the value of the corresponding key. |
Usage example:
sessionStore.set('username', 'tillo-dev');
console.log(sessionStore.get('username'));