示例#1
0
文件: view-post.ts 项目: cjdibbs/Blog
 activate(params : { date: string, title: string }, routeConfig) : void {
     this.post = this.app.posts.find(p => p.date === params.date && (p.title == params.title || p._title == params.title));
     routeConfig.navModel.setTitle(this.post.title);
     
     this.subscription = this.bindingEngine
         .propertyObserver(this.post, 'body')
         .subscribe(this.updateBody);
         
     if(this.post.body){
         this.updateBody(this.post.body);
     }
 }
 this.title = routeConfig.title.replace(/\{([^\}]+)\}/g, (match, path: string) => {
     let steps = path.split(".");
     let field = steps.pop();
     for (let step of steps) {
         entity = entity[step];
     }
     this.bindingEngine.propertyObserver(entity, field).subscribe(value => {
         this.title = routeConfig.title.replace(`{${path}}`, value);
         routeConfig.navModel.setTitle(this.title);
     });
     return entity[field];
 });
示例#3
0
    observe(properties, callback) {
        var subscriptions = [], i = properties.length, object, propertyName;
        while(i--) {
            object = properties[i][0];
            propertyName = properties[i][1];
            subscriptions.push(this.bindingEngine.propertyObserver(object, propertyName).subscribe(callback));
        }

        // return dispose function
        return {
            dispose: () => {
                while(subscriptions.length) {
                    subscriptions.pop().dispose();
                }
            }
        }
    }