Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventDispatcher を外部に公開して欲しい #268

Closed
3bch opened this issue Feb 17, 2014 · 3 comments
Closed

EventDispatcher を外部に公開して欲しい #268

3bch opened this issue Feb 17, 2014 · 3 comments
Assignees
Milestone

Comments

@3bch
Copy link

3bch commented Feb 17, 2014

h5.core.data.js に定義されている EventDispatcher を継承して独自のクラスを作成したいのですが、EventDispatcher を hifive の外から取得することができませんでした。

EventDispatcher を外部に公開してもらうことはできないでしょうか?

@simdy simdy added this to the v1.1.9 milestone Feb 25, 2014
@simdy simdy self-assigned this Feb 25, 2014
@simdy simdy modified the milestones: v1.1.10, v1.1.9 Mar 17, 2014
@simdy simdy assigned fukudayasuo and unassigned simdy Apr 30, 2014
@simdy
Copy link
Member

simdy commented Apr 30, 2014

Mix-in API(h5.u.obj.mix())を追加し、EventDispatcherをMixinの一つとして公開することとします。
EventDispatcherはh5.mixin.EventDispatcherMixinにて公開され、
h5.u.obj.mix(target, h5.mixin.EventDispatcherMixin)のように呼ぶと利用できます。
(targetは、EventDispatcher機能を追加するオブジェクトを指定してください。
 特定のオブジェクト全体に追加したい場合、prototypeプロパティのオブジェクトに対して使用することも可能です。)

@simdy
Copy link
Member

simdy commented Apr 30, 2014

Mix-inのAPIを変更します。
以下のように、h5.mixin.eventDispatcher.mix()メソッドを呼び出すようにしてください。

var obj = {};
h5.mixin.eventDispatcher.mix(obj);

fukudayasuo pushed a commit to hifive-labs/hifivemain that referenced this issue May 1, 2014
h5.mixinのテストケース作成しました。

hifive#268 h5.mixin.eventDispatcherを作成しました。
EventDispatcherをh5internalに公開してh5.mixin.jsで使用しています。
h5.mixin.eventDispatcherのテストは未追加です。
@fukudayasuo
Copy link

対応しました。

var obj = {};
h5.mixin.eventDispatcher.mix(obj);

でEventDispatcherの機能を持つオブジェクトを作成できます。

EventDispatcherの機能をプロトタイプに持つクラスを作成したい場合は、以下のようにprototypeオブジェクトにmixinすることで作成できます。

function MyClass(){
  /* コンストラクタ */
}
h5.mixin.eventDispatcher.mix(MyClass.prototype);

var myobj = new MyClass();

// myobjはEventDispatcherを継承しているので、以下のように使用可能
myobj.addEventListener('myevent', function(){/* イベントハンドラ */});
myobj.dispatchEvent('myevent');

@simdy simdy closed this as completed May 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants