Skip to content

Commit

Permalink
use new property mechanizm for Survey Model class:
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Aug 29, 2017
1 parent d719062 commit b7749c4
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 176 deletions.
27 changes: 26 additions & 1 deletion src/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export interface HashTable<T> {
import {ILocalizableOwner, LocalizableString} from "./localizablestring";

export interface HashTable<T> {
[key: string]: T;
}
export interface ISurveyData {
Expand Down Expand Up @@ -101,6 +103,7 @@ export class Base {
}

private propertyHash = {};
private localizableStrings = {};
private arrayOnPush = {};
protected isLoadingFromJsonValue: boolean = false;
public onPropertyChanged: Event<(sender: Base, options: any) => any, any> = new Event<(sender: Base, options: any) => any, any>();
Expand Down Expand Up @@ -151,6 +154,28 @@ export class Base {
if(this.isLoadingFromJson) return;
this.onPropertyChanged.fire(this, {name: name, oldValue: oldValue, newValue: newValue});
}
protected createLocalizableString(name: string, owner: ILocalizableOwner, useMarkDown: boolean = false): LocalizableString {
var locStr = new LocalizableString(owner, useMarkDown);
this.localizableStrings[name] = locStr;
return locStr;
}
protected getLocalizableString(name: string): LocalizableString {
return this.localizableStrings[name];
}
protected getLocalizableStringText(name: string, defaultStr: string = ""): string {
var locStr = this.getLocalizableString(name);
if(!locStr) return "";
var res = locStr.text;
return res ? res : defaultStr;
}
protected setLocalizableStringText(name: string, value: string) {
var locStr = this.getLocalizableString(name);
if(!locStr) return;
var oldValue = locStr.text;
if(oldValue === value) return;
locStr.text = value;
this.propertyValueChanged(name, oldValue, value);
}
protected createNewArray(name: string, onPush: any = null, onRemove: any = null): Array<any> {
var newArray = new Array<any>();
this.propertyHash[name] = newArray;
Expand Down
Loading

0 comments on commit b7749c4

Please sign in to comment.