OSDN Git Service

5c4f511f8b3ce930e2ad7bfaf2472fc57383f4e4
[bytom/Byone.git] / src / utils / Bytom.js
1 import Settings from './Settings';
2 import Keychain from './Keychain';
3 import Meta from './Meta';
4
5 export default class BytomObj {
6
7     constructor(){
8       this.meta = Meta.placeholder();
9       this.settings = Settings.placeholder();
10       this.keychain = Keychain.placeholder();
11       this.histories = [];
12     }
13
14     static placeholder(){ return new BytomObj(); }
15     static fromJson(json){
16         let p = Object.assign(this.placeholder(), json);
17         if(json.hasOwnProperty('meta')) p.meta = Meta.fromJson(json.meta);
18         if(json.hasOwnProperty('settings')) p.settings = Settings.fromJson(json.settings);
19         if(json.hasOwnProperty('keychain'))
20           p.keychain = (typeof json.keychain === 'string')
21             ? json.keychain : Keychain.fromJson(json.keychain);
22
23         return p;
24     }
25
26     clone(){ return BytomObj.fromJson(JSON.parse(JSON.stringify(this))) }
27 }