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

[TIMOB-7568] CommonJS in Core #1373

Merged
merged 3 commits into from
Feb 14, 2012
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions iphone/Classes/KrollBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ - (id) valueForUndefinedKey: (NSString *) key

-(KrollObject*)addModule:(NSString*)name module:(TiModule*)module
{
// Have we received a JS Module?
if (![module respondsToSelector:@selector(unboundBridge:)])
{
[modules setObject:module forKey:name];
return (KrollObject*)module;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A TiModule is a very different beast than a KrollObject. However, the best match is a KrollWrapper, but the relationships haven't been set up yet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, it would be best to change the method signature to return an id and avoid casting the module.

KrollObject *ko = [pageContext registerProxy:module];
if (ko == nil)
{
Expand Down
18 changes: 15 additions & 3 deletions iphone/Classes/TiHost.m
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,21 @@ -(id) moduleNamed:(NSString*)name context:(id<TiEvaluator>)context
if (moduleClass!=nil)
{
m = [[moduleClass alloc] _initWithPageContext:context];
[m setHost:self];
[modules setObject:m forKey:name];
[m release];
if (![m isJSModule])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm starting to wonder if we should refactor this so that all of moduleNamed goes straight to Require, do not pass go, do not collect $200. For one, the krollbridge require handles path-based module names while this version does not.

This is something we could revisit later, if needed. Something doesn't smell right about this, but I can't put my finger on it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does require that path always be toplevel, but I think that's expected for pre-compiled JS modules. The real question is whether or not this is intended to be used with pure JS modules that aren't precompiled into binary format - @dawsontoth can you give some input on that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my intention, at least for this pass at solving the problem. Long term, I think it would be great to not have to precompile them to binary. It would be even greater if we could have a single common location for pure JS modules to be loaded by both Android and iOS. But for this pass, it's not necessary at all. Does that answer your question, @sptramer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure does.

{
[m setHost:self];
[modules setObject:m forKey:name];
[m release];
}
else
{
[m release];
m = [[self krollBridge] require:context path:name];
if (m != nil)
{
[modules setObject:m forKey:name];
}
}
}
}

Expand Down