-
Notifications
You must be signed in to change notification settings - Fork 69
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
Mixing conventions + config #73
Comments
You need to ask @hij1nx |
Hey @hij1nx pretty please can I make this so? |
sorry, can you rephrase the problem, im not sure i completely understand. |
Sure thing, Basically, the current situation as I see it Plates.bind(html, model) Results in HTML which has been bound via convention, as it guesses where to place data based on class/id The algorithm for this looks something like this
Plates.bind(html, model, map) Results in HTML which has been bound via explicit configuration, as it uses the map to work out where to place data The algorithm for this looks something like this
Plates.bind(html, model, map) Results in HTML that has been bound via explicit configuration where available, and convention where not Algorithm for this looks something like
I actually made the assumption that this was how it worked, as it seems logical (and indeed the documentation for Weld - the project that came before this one seems to suggest that's how it worked) I could really do with this behaviour as I'm leaning towards using conventions for pretty much everything in this app, and treating the map as just another pile of custom conventions. |
Hey, any word on this? It's something we're working around for the moment with a file of bindings - it's not something we'd like to be doing long term. If we don't get word of whether the official project is going to take this behavior we'll go ahead and fork and it anyway :-) |
Ok, so from what I have gathered, you would prefer the bind method to explicitly require the map object? |
Hmm - no, I would prefer that if there is a map object present, for it to override the default behavior matching key name to class/id, but if there is no key in that map object then to try and map by class/id. I'm clearly having a failure to communicate here, are you at nodeconf summercamp in sept? I can show you code then if necessary :-) |
+1 to the request from @robashton. Here's a simple code example: var data = { foo: 'foo', 'complex-key-to-remap': 'bar' }
var html = '<div class='foo'></div><div class="remap"></div>'
var map = Plates.Map()
.class('remap').to('complex-key-to-remap');
console.log(Plates.bind(html, data, map)); This outputs: '<div class="foo"></div><div class="remap">bar</div>' Because passing an explicit map overrides any default mapping. What @robashton would like is that the default convention of mapping to '<div class="foo">foo</div><div class="remap">bar</div>' |
+1 btw, @indexzero, in your example, shouldn't you change in your data |
A very quick test seems to indicate that if you remove the |
@gravitezero You're right. Fixed. |
Ah cool, this is what we did in our forked copy too so we'll go ahead and throw that away - cheers! |
(Although iirc we changed the order because you want the map to override the conventions, not the other way around - I can't check this though as I'm not at the office) |
Exactly, the overriding part seems to be line 261. All the |
ah, this change sounds great, pull request anyone? ;) |
The change we made apparently breaks a few tests, I'll need to go through them and make sure it's all sane before sending you anything. Travelling this weekend, will see what I can do |
In most libraries where conventions are used, they're used as a default, on which further config can be placed.
Either I'm missing something or this is not the case in Plates, which is mildly annoying because it means for cases like
Will result in only the rel being mapped
Where as with the code previously
This worked fine and all the data got mapped by class beautifully.
I'm happy to make this change if it is agreed with.
The text was updated successfully, but these errors were encountered: