Skip to content

Commit 5331f02

Browse files
committed
Translate Observer
1 parent 42dcf3a commit 5331f02

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

README-ja-jp.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ _このドキュメントは[AngularJS in Patterns](https://github.com/mgechev/a
2828
* [コンポジット](#コンポジット)
2929
* [インタープリタ](#インタープリタ)
3030
* [テンプレート・ビュー](#テンプレート・ビュー)
31-
* [Scope](#scope-1)
32-
* [Observer](#observer)
31+
* [スコープ](#スコープ-1)
32+
* [オブザーバ](#オブザーバ)
3333
* [Chain of Responsibilities](#chain-of-responsibilities)
3434
* [Command](#command)
3535
* [Controller](#controller-1)
@@ -786,43 +786,43 @@ $scope.names = ['foo', 'bar', 'baz'];
786786

787787
これは、上記のものと同じ結果を出力します。ここでの主な違いはテンプレートが `script` にラップされていず、HTMLのままであるということです。
788788

789-
### Scope
789+
### スコープ
790790

791-
#### Observer
791+
#### オブザーバ
792792

793-
>The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. It is mainly used to implement distributed event handling systems.
793+
>オブザーバはサブジェクトと呼ばれるオブジェクトが依存しているオブザーバのリストを管理し、変更があったらオブザーバのメソッドを呼び出すことで通知するデザイン・パターンです。主に分散したイベント・ハンドリング・システムで利用されます。
794794
795795
![Observer](https://rawgit.com/mgechev/angularjs-in-patterns/master/images/observer.svg "Fig. 7")
796796

797-
There are two basic ways of communication between the scopes in an AngularJS application. The first one is calling methods of parent scope by a child scope. This is possible since the child scope inherits prototypically by its parent, as mentioned above (see [Scope](#scope)). This allows communication in a single direction - child to parent. Some times it is necessary to call method of given child scope or notify it about a triggered event in the context of the parent scope. AngularJS provides built-in observer pattern, which allows this. Another possible use case, of the observer pattern, is when multiple scopes are interested in given event but the scope, in which context the event is triggered, is not aware of them. This allows decoupling between the different scopes, non of the scopes should be aware of the rest of the scopes.
797+
AngularJSアプリケーションのスコープ間では主に2つの基本的なやりとりの方式があります。一つ目は子スコープが親スコープのメソッドを呼び出すことです。子スコープは親スコープをプロトタイプ継承しているのでこれが可能になります(参考: [スコープ](#スコープ) )。これは子から親への1方向のコミュニケーションです。時に、親スコープから子スコープのメソッドを呼び出したり、子スコープにイベントの通知を送りたい時があります。AngularJSはこれを実現するための組み込みのオブザーバ・パターンを用意しています。オブザーバ・パターンが必要とされる別のケースとして、複数のスコープがあるイベントに関心があるものの、そのイベントは別スコープにあるため気づけないというものがあります。別々のスコープ間の分離が行われているため、別のスコーぷの変更に気づくことができません。
798798

799-
Each AngularJS scope has public methods called `$on`, `$emit` and `$broadcast`. The method `$on` accepts topic as first argument and callback as second. We can think of the callback as an observer - an object, which implements the `Observer` interface (in JavaScript the functions are first-class, so we can provide only implementation of the `notify` method):
799+
それぞれのAngularJSのスコープは `$on``$emit` `$broadcast` と呼ばれるパブリック・メソッドを持っています。 `$on` メソッドは最初の引数として関心のある項目をとり、2つ目の引数としてコールバックをとります。このコールバックを `Observer` インターフェイスが実装されたオブザーバと考えることができます(JavaScriptでは関数は第一級オブジェクトなので、ただ、 `notify` メソッドを実装すればよいだけです):
800800

801801
```JavaScript
802802
function ExampleCtrl($scope) {
803803
$scope.$on('event-name', function handler() {
804-
//body
804+
//内容
805805
});
806806
}
807807
```
808808

809-
In this way the current scope "subscribes" to events of type `event-name`. When `event-name` is triggered in any parent or child scope of the given one, `handler` would be called.
809+
この方法で、現在のスコープは `event-name` のイベントを登録することができます。 `event-name` が親スコープや子スコープで実行された場合、 `handler` が呼ばれます。
810810

811-
The methods `$emit` and `$broadcast` are used for triggering events respectively upwards and downwards through the scope chain.
812-
For example:
811+
`$emit` メソッドと `$broadcast` メソッドはそれぞれスコープチェーンの上方向と下方向にイベントを伝播します。
812+
例えば:
813813

814814
```JavaScript
815815
function ExampleCtrl($scope) {
816816
$scope.$emit('event-name', { foo: 'bar' });
817817
}
818818
```
819819

820-
The scope in the example above, triggers the event `event-name` to all scopes upwards. This means that each of the parent scopes of the given one, which are subscribed to the event `event-name`, would be notified and their handler callback will be invoked.
820+
上記のスコープは、 `event-name` を上方向に伝播します。 `event-name` を登録している全ての親スコープは通知を受け、登録されているコールバックが実行されます。
821821

822-
Analogical is the case when the method `$broadcast` is called. The only difference is that the event would be transmitted downwards - to all children scopes.
823-
Each scope can subscribe to any event with multiple callbacks (i.e. it can associate multiple observers to given event).
822+
`$broadcast` が呼ばれたときも同様です。違いは、イベントの伝播が下方向(すべての子スコープ)に行くということです。
823+
それぞれのスコープが複数のコールバックを登録することができます(複数のオブザーバと関連することができます)。
824824

825-
In the JavaScript community this pattern is better known as publish/subscribe.
825+
JavaScriptコミュニティではこのパターンはパブリッシュ/サブスクライブとして知られています。
826826

827827
#### Chain of Responsibilities
828828

0 commit comments

Comments
 (0)