I have gone through lots of questions might be its repeat question.:(
exception i got -**"message":
"InvalidStateError: DOM Exception 11: This transaction is already finalized. Transactions are committed after its success or failure handlers are called. If you are using a Promise to handle callbacks, be aware that implementations following the A+ standard adhere to run-to-completion semantics and so Promise resolution occurs on a subsequent tick and therefore after the transaction commits."**
in React native android app i am getting values from offline data for appointment. in which i have done the lazy loading. my appointment limit is 10.
i have a flat list and i am checking the flatlist onEndReached properties.
in onEndReached properties i am getting the values from local database here is my function through which i am getting offline appointment values
GetAllAppointment(data) {
console.log("DATA IN -------->>", data);
return new Promise((resolve, reject) => {
this.initDB().then((db) => {
db.transaction((tx) => {
getObj('skipRecord', (id) => {
var skipRecord = ((data.pageNumber - 1) * 10);
let userAppointmentList = [];
tx.executeSql("Select * from ios_Appointment where date >= " + nowDate + " and clinicianId =" + data.UserID + " and fName Like '%" + data.searchKey + "%' OR lName Like '%" + data.searchKey + "%' OR address Like '%" + data.searchKey + "%' ORDER BY (date)").then(([tx, results]) => {
if (results.rows.length > 0) {
for (let i = skipRecord; i < results.rows.length; ++i) {
userAppointmentList.push(results.rows.item(i));
}
}
let pages;
pages = results.rows.length / records;
pages = Math.ceil(pages)
let items = {
"Version": "1.2.3",
"StatusCode": 200,
"Message": "Success",
"Result": userAppointmentList,
"pagesCount": pages
}
resolve(results);
}).then((result) => {
// this.closeDatabase(db);
}).catch((err) => {
console.log("GetAllAppointment 1---->>", err);
});
}).catch((err) => {
console.log("GetAllAppointment 2---->>", err);
});
}).catch((err) => {
});
}
i am calling above function to dashboard page where i am adding this return appointment to Flalist
const db = new Database();
export default class DashboardPage extends Component {
this.page = 1;
.
.
.
handleLoadMore = () => {
if (!this.state.showLoader && (this.state.pageCount > this.page)) {
console.log("handleLoadMore page if------------------>>> ", this.state.showLoader);
this.page = this.page + 1;
this.setState({ showBottomLoader: true });
this.getData(page);
}
.
.
.
getData(body) {
let body = {
"pageNumber": page,
"searchKey": this.state.searchText,
"UserID": 1,
"currentDate": new Date().getTime()
}
db.GetAllAppointment(body).then((item) => {
let newData;
if (item) {
if (body.pageNumber == 1) {
newData = item.Result;
this.state.appointmentList.concat(item.Result)
} else {
newData = this.state.appointmentList.concat(item.Result)
}
this.setState({
showLoader: false,
appointmentList: newData,
pageCount: item.pagesCount,
showBottomLoader: false,
isRefreshing: false
})
}
}).catch((err) => {
this.setState({
showLoader: false,
appointmentList: newData,
pageCount: item.pagesCount,
showBottomLoader: false,
isRefreshing: false
})
})
first time i am getting 10 records but then i am getting the DOM exception how to solve this problem :( thanks in advance
finally its solved.
GetAllAppointment(data) {
console.log("DATA IN -------->>", data);
return new Promise((resolve, reject) => {
this.initDB().then((db) => {
getObj('skipRecord', (id) => {
db.transaction((tx) => {
before transaction i am checking my skip-record value which is stored locally and then upon id executing the db.transaction now finally stop getting the DOM Exception :)