Skip to content

Instantly share code, notes, and snippets.

@twolfson
Created January 18, 2013 12:47
Show Gist options
  • Save twolfson/4564351 to your computer and use it in GitHub Desktop.
Save twolfson/4564351 to your computer and use it in GitHub Desktop.
Thoughts from 07/15/12 on partials (much has changed since then)

Post

Improving partials (inspired by Jade’s mixins) [07/15] -- Inline’d partials as functions is what we really want: <%= Builder(‘partialView’, app) %> The current setup is too watered down to have any real power. Unfortunately, if we want to use Jade mixins globally, they must be defined globally as such which kills the ability for segmentation and re-use in other parts (a rose by any other name). Otherwise, it is local which is the same as our current state. So fucking simple yet so fucking powerful and easy to miss.

Comment #1

Making this happen: In every Builder invocation, include a new object property:

{
  // I have decided to rename Builder to partial for semantics
  // The syntax will still be <%= partial('viewName', app); %>
  'partial': function (view, data) {
    // Runs through template engine (no 'UI' binding here as it is done in its parent)
  }
}

For looking up views, we have a few options:

  1. Pass in views to the Builder (e.g. Builder(html, {'views': {'partial1': partialHtml}}) -- not preferred since need to re-do every time
  2. Synchronous global store of all views: 2.a. Inside of the mvc.js plugin, we can define('views', {}) and add each view to it as they are retrieved 2.b. Look up directly in require.js (require.s._.contexts...)
  3. Pass in partialHtml to the view so it would go
var $html = Builder(html, {'myPartial': myPartialHtml});

<%= partial(myPartial, app); %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment