
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-native-models
Advanced tools
Implementation of the models for React Native. Allow serialize/deserialize classes and store them in AsyncStorage.
Implementation of the models for React Native.
constructor(properties: object): Model
Create instance of Model. Properties is a plain object:
{
number: "Number",
string: "String",
boolean: "Boolean",
object: "Object",
array: "Array",
modelBase: "Model",
}
store(key?:string): Promise
Save model in Storage. This method serialize model and all nested models. If key doesn't specified used className property. Key support path syntax. For example:
/book/0
/book/1
/book/2
static restore(key?:string): Promise
Restore model from Storage. If key doesn't specified using className property. If store models with keys /book/0 and /book/1, possible to restore them by /book/* key.
static remove(key?:string): Promise
Remove value from Store and related record in _items record.
serialize(): string
Serialize object.
static deserialize(): Model
Deserialize object from string.
populateFromState(state: object)
Fill model's properties from given state.
static fromState(state: object): Model
Create new instance of Model. This method check type whenever set model's property.
static require(constructor: Model)
Bind class name with its constructor. Need for deserialization.
import Model from "react-native-models";
export default class MyModel extends Model {
// className used instead name because babel replaces him at run-time.
static get className() {
return "MyModel";
}
constructor(a = 0, b = "foo", c = new Model()) {
super({
a: "Number",
b: "String",
c: "Model" // Nested model
});
// Now MyModel has two members
// this._a === null
// this._b === null
this._a = a; // this._a === 0
this._b = b; // this._b === "foo"
this._c = c; // this._c === instanceOf Model
// or with validation of type
this.setA(a);
this.setB(b);
this.setC(c);
}
test() {
this.setA(1);
this.setB("bar");
const a = this.getA(); // a === 1
const b = this.getB(); // b === "bar"
try {
this.setA("1");
} catch (error) {
return "exception";
}
return "no exception";
}
}
const myModel = new MyModel();
myModel.setA(10);
myModel.store().then(() => {
// ok
}).catch((error) => {
// handle error
});
MyModel.restore().then((myModel) => {
// ok
}).catch((error) => {
// handle error
});
const myModel = new MyModel(1, "My model");
const anotherModel = new MyModel(2, "Another model");
myModel.store("/myModel").then(() => {
return anotherModel.store("/anotherModel");
}).then(() => {
MyModel.require(MyModel);
return MyModel.restore("/*");
}).then((models) => {
const myModel = models[0];
const anotherModel = model[1];
// myModel.getA() === 1
// myModel.getB() === "My model"
// anotherModel.getA() === 2
// anotherModel.getB() === "Another model"
});
import React from "react";
import Model from "react-native-models";
import MyModel from "./MyModel";
export default class MyComponent extends React.Component {
constructor(props) {
super(props);
// Use default values of model
this.state = (new MyModel()).createState();
}
componentWillMount() {
// Required for instancing of models objects.
MyModel.require(MyModel);
MyModel.restore().then((myModel) => {
if (myModel!== null) {
this.setState(myModel.createState());
}
}).catch((error) => {
// error handling
});
}
}
const myModel = new MyModel();
const serialized = myModel.serialize();
const myModel2 = MyModel.deserialize(serialized);
echo '{ "presets": ["es2015"] }' > .babelrc
npm test
FAQs
Implementation of the models for React Native. Allow serialize/deserialize classes and store them in AsyncStorage.
We found that react-native-models demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.