Store

어플리케이션 수준에서 공유되어야 할 데이타 저장소로서 Store 를 제공합니다. Store 를 만든 후 간단하게 어플리케이션에 등록하면 모든 뷰에서 언제든 참조할 수 있습니다.

import Woowahan from 'woowahan';

const app = new Woowahan();

const store = Woowahan.Store.create({
  appInfo: {
    version: '1.0',
    env: 'production'
  },
  profile: {
    id: 'Foo',
    name: 'Foo bar zoo'
  }  
});

// 등록
app.use(store);

개별 뷰에서 다음과 같이 접근하여 사용할 수 있습니다.

import Woowahan from 'woowahan';

Woowahan.View.create('view', {

  initialize() {
    const { profile, appInfo }= this.getStates();

    this.setModel({ profile, appInfo });

    this.super();
  },

  onUpdateProfile() {
    const profile = this.getModel('profile');

    profile.name = 'FOO';

    this.setStates('profile', profile);
  }
});

results matching ""

    No results matching ""