diff --git a/app/Jasonette/Jason.m b/app/Jasonette/Jason.m index 248a1089..e1d7e30d 100644 --- a/app/Jasonette/Jason.m +++ b/app/Jasonette/Jason.m @@ -52,6 +52,12 @@ - (id)init { name:@"Jason.error" object:nil]; + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(notifyCall:) + name:@"Jason.call" + object:nil]; + } return self; } @@ -69,6 +75,12 @@ - (void)notifyError:(NSNotification *)notification { [[Jason client] error:args]; } +- (void)notifyCall:(NSNotification *)notification { + NSDictionary *args = notification.object; + NSLog(@"JasonCore: notifyCall: %@", args); + [[Jason client] call:args]; +} + #pragma mark - Jason Core API (USE ONLY THESE METHODS TO ACCESS Jason Core!) @@ -622,6 +634,8 @@ - (Jason *)attach:(UIViewController*)viewController{ VC.url = [VC.url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; + VC.modules = [[NSMutableDictionary alloc] init]; + // Set the stylesheet if(VC.style){ JasonComponentFactory.stylesheet = [VC.style mutableCopy]; @@ -2335,7 +2349,12 @@ - (void)exec{ NSLog(@"Plugin: class: %@", PluginClass); // Initialize Plugin - module = [[PluginClass alloc] init]; // could go away if we had some sort of plug in registration + if(VC.modules && VC.modules[type]){ + module = modules[type]; + } else { + module = [[PluginClass alloc] init]; // could go away if we had some sort of plug in registration + VC.modules[type] = module; + } [[NSNotificationCenter defaultCenter] postNotificationName:plugin_path @@ -2386,7 +2405,13 @@ - (void)exec{ NSString *methodName = tokens[1]; SEL method = NSSelectorFromString(methodName); - module = [[ActionClass alloc] init]; + if(VC.modules && VC.modules[type]){ + module = modules[type]; + } else { + module = [[ActionClass alloc] init]; // could go away if we had some sort of plug in registration + VC.modules[type] = module; + } + if([module respondsToSelector:@selector(VC)]) [module setValue:VC forKey:@"VC"]; if([module respondsToSelector:@selector(options)]) [module setValue:[self options] forKey:@"options"]; [module performSelector:method]; diff --git a/app/Jasonette/JasonViewController.h b/app/Jasonette/JasonViewController.h index c78a9de0..3a62922f 100644 --- a/app/Jasonette/JasonViewController.h +++ b/app/Jasonette/JasonViewController.h @@ -40,6 +40,7 @@ @property (strong, nonatomic) NSDictionary *parser; @property (nonatomic, strong) NSDictionary *data; +@property (strong, nonatomic) NSMutableDictionary *modules; @property (nonatomic, strong) NSMutableArray *sections; @property (nonatomic, strong) NSArray *rows; diff --git a/app/Jasonette/JasonViewController.m b/app/Jasonette/JasonViewController.m index 8e718e53..a981c621 100644 --- a/app/Jasonette/JasonViewController.m +++ b/app/Jasonette/JasonViewController.m @@ -86,6 +86,7 @@ - (void)viewDidLoad { self.callback = [[NSDictionary alloc] init]; self.sections = [[NSMutableArray alloc] init]; self.rows = [[NSArray alloc] init]; + self.modules = [[NSMutableDictionary alloc] init]; self.form = [[NSMutableDictionary alloc] init]; self.tableView.delaysContentTouches = false; diff --git a/app/Jasonette/RussianDollView.h b/app/Jasonette/RussianDollView.h index e0c43560..12ba8152 100644 --- a/app/Jasonette/RussianDollView.h +++ b/app/Jasonette/RussianDollView.h @@ -11,6 +11,7 @@ @property (nonatomic, strong) NSString *url; @property (nonatomic, strong) NSDictionary *data; @property (nonatomic, strong) NSDictionary *options; +@property (nonatomic, strong) NSMutableDictionary *modules; @property (nonatomic, strong) NSDictionary *parser; @property (nonatomic, strong) NSDictionary *callback; @property (nonatomic, strong) NSDictionary *nav;