Skip to content

Commit

Permalink
Added mobx-state-tree models
Browse files Browse the repository at this point in the history
  • Loading branch information
abritopach committed Feb 22, 2018
1 parent 4720f0d commit 3bd7d12
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
"ionic-angular": "^3.9.2",
"ionic-plugin-keyboard": "^2.2.1",
"ionicons": "3.0.0",
"mobx": "^3.5.1",
"mobx-angular": "^2.1.1",
"mobx-state-tree": "^1.3.1",
"papaparse": "^4.3.6",
"rxjs": "5.5.2",
"survey-angular": "^0.12.4",
Expand Down
Binary file modified readme_resources/app.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions src/models/survey.mst.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { types, flow, applySnapshot } from 'mobx-state-tree';
import { SurveyProvider } from '../providers/survey/survey';

export const Survey = types.model({
AllowAccessResult: types.boolean,
CreatedAt: types.string,
CreatorId: types.string,
Id: types.string,
IsArchived: types.boolean,
IsPublished: types.boolean,
Name: types.string,
PostId: types.string,
PublishId: types.maybe(types.string),
ResultId: types.string,
StoreIPAddress: types.boolean,
UseCookies: types.boolean,
UserId: types.string,
Image: types.optional(types.string, '')
}).actions(self => ({

}));

export const SurveyList = types.model({
surveys: types.optional(types.array(Survey), []),
}).actions(self => ({
getActiveSurveys(surveyProvider: SurveyProvider) { // <- note the star, this a generator function!
console.log('getActiveSurveys');
surveyProvider.getActiveSurveys()
.subscribe(
data => {
console.log(data);
applySnapshot(self.surveys, data);
},
error => {
console.log(<any>error);
}
);
}
})).views(self => ({
getSurveysCount() {
return self.surveys.reduce((count, entry) => count + 1, 0);
}
}));
13 changes: 13 additions & 0 deletions src/pages/home/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { ApiWrapper } from '../../providers/survey/api-wrapper';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/forkJoin';

import { SurveyList } from '../../models/survey.mst.model';

@Component({
selector: 'page-home',
templateUrl: 'home.html'
Expand All @@ -22,6 +24,9 @@ export class HomePage {
noSurveys: boolean = false;
currentYear = new Date().getFullYear();

surveysMobx: any;


constructor(public navCtrl: NavController, public surveyProvider: SurveyProvider,
public loadingCtrl: LoadingController, public alertCtrl: AlertController, public apiWrapper: ApiWrapper) {
//this.getActiveSurveys();
Expand All @@ -40,6 +45,14 @@ export class HomePage {
}
);
*/

/*
this.surveysMobx = SurveyList.create({
surveys: []
});
this.surveysMobx.getActiveSurveys(this.surveyProvider);
*/

}

Expand Down

0 comments on commit 3bd7d12

Please # to comment.