| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library trydart.compilationUnit; | |
| 6 | |
| 7 import 'dart:async' show | |
| 8 Stream, | |
| 9 StreamController; | |
| 10 | |
| 11 class CompilationUnitData { | |
| 12 final String name; | |
| 13 String content; | |
| 14 | |
| 15 CompilationUnitData(this.name, this.content); | |
| 16 } | |
| 17 | |
| 18 class CompilationUnit extends CompilationUnitData { | |
| 19 // Extending [CompilationUnitData] allows this class to hide the storage | |
| 20 // allocated for [content] without introducing new names. The conventional | |
| 21 // way of acheiving this is to introduce a library-private field, but library | |
| 22 // privacy isn't without problems. | |
| 23 | |
| 24 static StreamController<CompilationUnit> controller = | |
| 25 new StreamController<CompilationUnit>(sync: false); | |
| 26 | |
| 27 static Stream<CompilationUnit> get onChanged => controller.stream; | |
| 28 | |
| 29 CompilationUnit(String name, String content) | |
| 30 : super(name, content); | |
| 31 | |
| 32 void set content(String newContent) { | |
| 33 if (content != newContent) { | |
| 34 super.content = newContent; | |
| 35 controller.add(this); | |
| 36 } | |
| 37 } | |
| 38 } | |
| OLD | NEW |