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

Fix missing componentName in DoughBaseComponent #219

Merged
merged 19 commits into from
May 13, 2015

Conversation

ourmaninamsterdam
Copy link
Contributor

This PR accomplishes the following:

  • Enables a component to be instantiated using its constructor and stamped (new FooComponent()) without using componentLoader. Before initialising a component directly would return stamp data-dough-undefined-initialised="yes". It now properly sets data-dough-foo-initialised="yes". It does this by moving responsibility of setting the componentName to DoughBaseComponent. See componentname is not being set in DoughBaseComponent #218 for the original bug.
  • Adds componentName's to default Dough components
  • Adds specs for DoughBaseComponent

@ourmaninamsterdam
Copy link
Contributor Author

Found this to get function name which would avoid the need to specify the componentName: https://gist.github.com/ourmaninamsterdam/53e5b87167a411ada149

var warning;

if (typeof componentName !== 'undefined') {
if (this.$el.data('dough-component').indexOf(componentName)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need indexOf(componentName) >= -1?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry > -1

@ourmaninamsterdam ourmaninamsterdam force-pushed the fix-missing-component-name branch 5 times, most recently from 9baa951 to 43743da Compare February 25, 2015 16:21
@ourmaninamsterdam ourmaninamsterdam changed the title [WIP][DO NOT MERGE] Check for missing component name Fix missing componentName in DoughBaseComponent Feb 26, 2015
* @returns {string} eg. tab-selector
*/
convertCamelCaseToDashed: function(str) {
var val = str.replace(/[A-Z]/g, function(match) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I realise you've just moved this function but it currently doesn't handle cases like `MASComponent' correctly

@alexwllms
Copy link
Contributor

LGTM 👍

@@ -2,6 +2,13 @@ describe('componentLoader', function() {

'use strict';

function convertCamelCaseToDashed(str) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does copying this code to the spec actually test anything? If the production code has an issue, so does the test and it isn't caught.

@ourmaninamsterdam ourmaninamsterdam changed the title Fix missing componentName in DoughBaseComponent [DO NOT MERGE] - Fix missing componentName in DoughBaseComponent Mar 5, 2015
@benbarnett
Copy link
Contributor

This looks great 👍

@ourmaninamsterdam ourmaninamsterdam changed the title [DO NOT MERGE] - Fix missing componentName in DoughBaseComponent Fix missing componentName in DoughBaseComponent May 8, 2015
@ourmaninamsterdam
Copy link
Contributor Author

@benbarnett We discussed the dependency resolution issues that could occur when including the utilities.js dependency from DoughBaseComponent.js and how we could get around these. I've done some testing and it works fine if you specify utilities.js in frontend's require_config.js.erb config with a mounted engine (pensions calc in my tests), but if you run the engine standalone and don't specify this in the engine's require_config.js.erb then Cucumber blows up. Short of including utilities.js in each of the engines JS configs, can you think of any other ways around this?

@benbarnett
Copy link
Contributor

Hmm, yeah sadly this will only work when the engines are mounted, as they inherit the require config from frontend. We'd need to add them individually to the engines to get their tests to pass.

I suppose an alternative could just be to merge utilities into DoughBaseComponent?

@benbarnett
Copy link
Contributor

Just discussed this in person, including the utilities module directly into the ComponentLoader.js file (via sprockets, not RequireJS) seems to have made this simpler.

@benbarnett
Copy link
Contributor

Travis failing is an issue separate to this and shouldn't hold up the merge. I've run the tests locally and all looks good 👍

@@ -34,6 +34,8 @@ define(['jquery', 'DoughBaseComponent'], function($, DoughBaseComponent) {

DoughBaseComponent.extend(FieldHelpText);

FieldHelpText.componentName = 'FieldHelpText';
Copy link
Contributor

Choose a reason for hiding this comment

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

Weird indentation here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

ourmaninamsterdam added a commit that referenced this pull request May 13, 2015
…-name

Fix missing componentName in DoughBaseComponent
@ourmaninamsterdam ourmaninamsterdam merged commit cf4e4cb into master May 13, 2015
@ourmaninamsterdam ourmaninamsterdam deleted the fix-missing-component-name branch May 13, 2015 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants