Permalink
Browse files

Lazy instantiation.

  • Loading branch information...
1 parent c8e35f8 commit bfeaa6a52b935e49d4fb1c484ea3e20f15c8aed2 Peter Bergstrom committed with Charles Jolley Oct 5, 2009
Showing with 63 additions and 9 deletions.
  1. +10 −6 Buildfile
  2. +2 −0 buildtasks/manifest.rake
  3. +1 −1 frameworks/sproutcore
  4. +23 −0 lib/sproutcore/builders/combine.rb
  5. +27 −2 lib/sproutcore/builders/javascript.rb
View
@@ -57,7 +57,7 @@ mode :all do
# Generate a combined javascript and stylesheet
:combine_javascript => true,
:combine_stylesheets => true,
-
+
# by default all targets autobuild
:autobuild => true,
@@ -77,6 +77,10 @@ mode :all do
:bootstrap_inline => 'sproutcore/bootstrap:javascript',
:use_packed => true,
+
+ # If set to true, the specified framework, if loaded via the SC.loadBundle
+ # API, will be set up to be lazily instantiated when loaded.
+ :lazy_instantiation => false,
# if set to true then the index.html will build into the global language
# and target directory. This can interfere with deploying multiple builds
@@ -95,17 +99,17 @@ mode :debug do
config :all,
# in debug mode, load fixtures, debug, tests, and protocols
- :load_fixtures => true,
- :load_debug => true,
- :load_tests => true,
+ :load_fixtures => false,
+ :load_debug => false,
+ :load_tests => false,
:load_protocols => true,
# Do not combine javascript and stylesheet
:combine_javascript => false,
- :combine_stylesheets => true,
+ :combine_stylesheets => false,
:minify_javascript => false,
- :minify_css => false,
+ :minify_css => false,
:build_prefix => 'tmp/debug/build',
:staging_prefix => 'tmp/debug/staging',
View
@@ -199,6 +199,7 @@ namespace :manifest do
# add transform & tag with build directives.
entries.each do |entry|
entry = MANIFEST.add_transform entry,
+ :lazy_instantiation => CONFIG.lazy_instantiation,
:notify_onload => !CONFIG.combine_javascript,
:filename => ['source', entry.filename].join('/'),
:build_path => File.join(MANIFEST.build_root, 'source', entry.filename),
@@ -317,6 +318,7 @@ namespace :manifest do
MANIFEST.add_composite resource_name,
:build_task => 'build:combine',
:source_entries => entries,
+ :top_level_lazy_instantiation => CONFIG.lazy_instantiation,
:hide_entries => CONFIG.combine_javascript,
:ordered_entries => SC::Helpers::EntrySorter.sort(entries, pf),
:entry_type => :javascript,
Submodule sproutcore updated 508 files
@@ -21,6 +21,21 @@ def build(dst_path)
lines = []
entries = entry.ordered_entries || entry.source_entries
+ target_name = entry.target.target_name.to_s.sub(/^\//,'')
+ if entry.top_level_lazy_instantiation && entry.combined
+ lines << ";
+if ((typeof SC !== 'undefined') && SC && !SC.LAZY_INSTANTIATION) {
+ SC.LAZY_INSTANTIATION = {};
+}
+if(!SC.LAZY_INSTANTIATION['#{target_name}']) {
+ SC.LAZY_INSTANTIATION['#{target_name}'] = [];
+}
+SC.LAZY_INSTANTIATION['#{target_name}'].push(
+ (
+ function() {
+"
+ end
+
entries.each do |entry|
src_path = entry.stage!.staging_path
next unless File.exist?(src_path)
@@ -29,6 +44,14 @@ def build(dst_path)
lines += readlines(src_path)
lines << "\n"
end
+
+ if entry.top_level_lazy_instantiation && entry.combined
+ lines << "
+ }
+ )
+);
+"
+ end
writelines dst_path, lines
end
@@ -17,13 +17,38 @@ module SC
class Builder::JavaScript < Builder::Base
def build(dst_path)
- lines = readlines(entry.source_path).map { |l| rewrite_inline_code(l) }
+ lines = []
+ target_name = entry.target.target_name.to_s.sub(/^\//,'')
+
+ if entry.lazy_instantiation && entry.notify_onload
+ lines << ";
+if ((typeof SC !== 'undefined') && SC && !SC.LAZY_INSTANTIATION) {
+ SC.LAZY_INSTANTIATION = {};
+}
+if(!SC.LAZY_INSTANTIATION['#{target_name}']) {
+ SC.LAZY_INSTANTIATION['#{target_name}'] = [];
+}
+SC.LAZY_INSTANTIATION['#{target_name}'].push(
+ (
+ function() {
+"
+ end
+
+ lines << readlines(entry.source_path).map { |l| rewrite_inline_code(l) }
# Try to load dependencies if we're not combining javascript.
if entry.notify_onload
- lines << "; if ((typeof SC !== 'undefined') && SC && SC.scriptDidLoad) SC.scriptDidLoad('#{entry.target.target_name.to_s.sub(/^\//,'')}');"
+ lines << "; if ((typeof SC !== 'undefined') && SC && SC.scriptDidLoad) SC.scriptDidLoad('#{target_name}');"
end
+ if entry.lazy_instantiation && entry.notify_onload
+ lines << "
+ }
+ )
+);
+"
+ end
+
writelines dst_path, lines
end

0 comments on commit bfeaa6a

Please sign in to comment.