Saturday, March 10, 2012

Shhh! Silent Announce of Hipster MVC (Dart)

‹prev | My Chain | next›

As of last night, I have a somewhat functional router for my somewhat functional MVC library written in Dart. There are still some huge gaps in Hipster MVC, but I need to begin the process of whipping it into shape for reference in Dart for Hipsters, so, without further adieu, I announce Hipster MVC. Please don't tell anyone.

I will copy what few tests I have for it later. For tonight, I hope to verify that the application from which it was extracted still works without the libraries embedded in it. So I work through each of the classes in my MVC comic book collection app and replace the local #import() statements with the equivalent referencing the new Github location:
#library('Form view to add new comic book to my sweet collection.');

#import('dart:html');

#import('https://raw.github.com/eee-c/hipster-mvc/master/HipsterView.dart');

class AddComicForm extends HipsterView {
  // ...
}
After making the switch on each of my models, views, and collections (Emacs makes it easy), I load the app in Dartium to find:


It still works. Yay!

Based on the console output, it seems that Github is not aware of the Dart mime-type, but no matter. Dartium still handles the scripts just fine.

When I load up my router sample app after switching to the Github libraries, I am greeted with an error from my Router:
Exception: NoSuchMethodException : method not found: 'get:HipsterHistory'
Receiver: Instance of 'MyRouter'
Arguments: []
Stack Trace:  0. Function: 'Object.noSuchMethod' url: 'bootstrap' line:669 col:3
 1. Function: 'HipsterRouter.function' url: 'https://raw.github.com/eee-c/hipster-mvc/master/HipsterRouter.dart' line:17 col:22
 2. Function: 'GrowableObjectArray.forEach' url: 'bootstrap_impl' line:1256 col:8
 3. Function: 'HipsterRouter._initializeRoutes@2e7aef38' url: 'https://raw.github.com/eee-c/hipster-mvc/master/HipsterRouter.dart' line:16 col:19
 4. Function: 'HipsterRouter.HipsterRouter.' url: 'https://raw.github.com/eee-c/hipster-mvc/master/HipsterRouter.dart' line:10 col:27
 5. Function: 'MyRouter.MyRouter.' url: 'file:///home/cstrom/repos/dart-book/book/includes/push_state/main.dart' line:18 col:1
 6. Function: '::main' url: 'file:///home/cstrom/repos/dart-book/book/includes/push_state/main.dart' line:7 col:23
Ah, that was my fault. When I extracted the HipsterHistory and HipsterRouter libaries out into separate class files, I forgot that the router needs to be able to manipulate the history. So, in the HipsterRouter.dart file in my new library, I #import() the necessary library:
#library('Router for MVC pages.');

#import("dart:html");

#import("HipsterHistory.dart");

class HipsterRouter {
  // ...
}
After pushing the change to Github, my routing sample app is again working properly:


What is cool about this is that, in my library files, I #import() relative to the files on Github. That is, there is no host or path information in the import: #import("HipsterHistory.dart"). But when I reference the libraries in my local app, I have to include the full path:
#import("dart:html");

#import("https://raw.github.com/eee-c/hipster-mvc/master/HipsterRouter.dart");
#import("https://raw.github.com/eee-c/hipster-mvc/master/HipsterHistory.dart");

main() {
  HipsterRouter app = new MyRouter();
  HipsterHistory.startHistory();
}
What is cool is that Dart is smart enough to know that both #import() statements reference the same library file and, as such, that there is not need to re-request:


The last thing that I try tonight is to compile these Github served libraries into Javascript. Unfortunately, that does not quite work:
➜  push_state git:(master) ✗ frogc main.dart 
error: File not found: https:/raw.github.com/eee-c/hipster-mvc/master/HipsterRouter.dart
error: File not found: https:/raw.github.com/eee-c/hipster-mvc/master/HipsterHistory.dart
main.dart:18:24: error: cannot find type HipsterRouter
class MyRouter extends HipsterRouter {
                       ^^^^^^^^^^^^^

.... more invalid reference warnings

compilation failed with 4 errors
Compilation failed
Ah well, it was worth a shot. I am using a somewhat old version of frogc so I might try upgrading tomorrow to see if that helps.

I am not too fussed about not being able to compile remote resources. That will get fixed at some point (if it has not already been fixed). Besides, I would imagine that, were this a real app, I would manually copy the Hipster MVC resources directly into my scripts directory. I know that compilation already works there.

That minor glitch aside, this was a very successful move. Just please don't tell anyone about this. This library really needs some work before it is ready for prime time.


Day #321

1 comment: