Skip to content

Commit 3637eb4

Browse files
Merge pull request #118 from opencomponents/remove-rendered-logic
remove logic of api returning a "rendered" response as it can't happen
2 parents 267858a + 01b0077 commit 3637eb4

File tree

3 files changed

+17
-118
lines changed

3 files changed

+17
-118
lines changed

src/oc-client.js

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ var oc = oc || {};
8383
MESSAGES_ERRORS_RETRY_FAILED =
8484
'Failed to load $0 component ' + RETRY_LIMIT + ' times. Giving up',
8585
MESSAGES_ERRORS_LOADING_COMPILED_VIEW = 'Error getting compiled view: $0',
86-
MESSAGES_ERRORS_GETTING_DATA = 'Error getting data',
8786
MESSAGES_ERRORS_RENDERING = 'Error rendering component: $1, error: $0',
8887
MESSAGES_ERRORS_RETRIEVING =
8988
'Failed to retrieve the component. Retrying in ' +
@@ -277,9 +276,6 @@ var oc = oc || {};
277276
crossDomain: true,
278277
success: function (apiResponse) {
279278
var response = apiResponse[0].response;
280-
if (response.renderMode == 'rendered') {
281-
return cb(MESSAGES_ERRORS_GETTING_DATA);
282-
}
283279
var err = response.error ? response.details || response.error : null;
284280
cb(err, response.data, apiResponse[0]);
285281
},
@@ -530,49 +526,24 @@ var oc = oc || {};
530526
crossDomain: true,
531527
success: function (apiResponse) {
532528
var template = apiResponse.template;
533-
if (apiResponse.renderMode == 'unrendered') {
534-
apiResponse.data.id = id;
535-
oc.render(template, apiResponse.data, function (err, html) {
536-
if (err) {
537-
callback(
538-
interpolate(
539-
MESSAGES_ERRORS_RENDERING,
540-
err,
541-
apiResponse.href
542-
)
543-
);
544-
} else {
545-
logInfo(interpolate(MESSAGES_RENDERED, template.src));
546-
callback(null, {
547-
id: id,
548-
html: html,
549-
baseUrl: apiResponse.baseUrl,
550-
key: template.key,
551-
version: apiResponse.version,
552-
name: apiResponse.name
553-
});
554-
}
555-
});
556-
} else if (apiResponse.renderMode == 'rendered') {
557-
logInfo(interpolate(MESSAGES_RENDERED, apiResponse.href));
558-
559-
if (apiResponse.html.indexOf('<' + OC_TAG) == 0) {
560-
var innerHtmlPlusEnding = apiResponse.html.slice(
561-
apiResponse.html.indexOf('>') + 1
562-
),
563-
innerHtml = innerHtmlPlusEnding.slice(
564-
0,
565-
innerHtmlPlusEnding.lastIndexOf('<')
566-
);
567-
568-
apiResponse.html = innerHtml;
529+
apiResponse.data.id = id;
530+
oc.render(template, apiResponse.data, function (err, html) {
531+
if (err) {
532+
callback(
533+
interpolate(MESSAGES_ERRORS_RENDERING, err, apiResponse.href)
534+
);
535+
} else {
536+
logInfo(interpolate(MESSAGES_RENDERED, template.src));
537+
callback(null, {
538+
id: id,
539+
html: html,
540+
baseUrl: apiResponse.baseUrl,
541+
key: template.key,
542+
version: apiResponse.version,
543+
name: apiResponse.name
544+
});
569545
}
570-
callback(null, {
571-
html: apiResponse.html,
572-
version: apiResponse.version,
573-
name: apiResponse.name
574-
});
575-
}
546+
});
576547
},
577548
error: function (err) {
578549
if (err && err.status == 429) {

test/get-data.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -148,30 +148,6 @@ describe('oc-client : getData', function () {
148148
);
149149
});
150150

151-
it('should call the callback with an error if the registry responds with a rendered component', function (done) {
152-
oc.$.ajax = function (options) {
153-
return options.success([
154-
{ response: { renderMode: 'rendered', data: 'hello' } }
155-
]);
156-
};
157-
158-
execute(
159-
{
160-
baseUrl: 'http://www.components.com/v2',
161-
name: 'myComponent',
162-
version: '6.6.6',
163-
parameters: {
164-
name: 'evil'
165-
}
166-
},
167-
function (err, data) {
168-
expect(err).toEqual('Error getting data');
169-
expect(data).toEqual(undefined);
170-
done();
171-
}
172-
);
173-
});
174-
175151
describe('when json is requested', function () {
176152
it('should call the $.ajax method correctly', function (done) {
177153
var spy = sinon.spy(oc.$, 'ajax');

test/render-by-href.js

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -158,54 +158,6 @@ describe('oc-client : renderByHref', function () {
158158
});
159159
});
160160

161-
describe('when the registry responds with rendered component with container', function () {
162-
var callback;
163-
beforeEach(function () {
164-
callback = sinon.spy();
165-
initialise(renderedResponse);
166-
eval(compiledViewContent);
167-
oc.renderByHref(route, callback);
168-
});
169-
170-
afterEach(cleanup);
171-
172-
it('should respond without an error', function () {
173-
expect(callback.args[0][0]).toBe(null);
174-
});
175-
176-
it('should respond with the rendered html', function () {
177-
expect(callback.args[0][1].html).toEqual('Hello, world!!!');
178-
});
179-
180-
it('should respond with the correct version', function () {
181-
expect(callback.args[0][1].version).toEqual('1.2.123');
182-
});
183-
});
184-
185-
describe('when the registry responds with rendered component without container', function () {
186-
var callback;
187-
beforeEach(function () {
188-
callback = sinon.spy();
189-
initialise(renderedNoContainerResponse);
190-
eval(compiledViewContent);
191-
oc.renderByHref(route, callback);
192-
});
193-
194-
afterEach(cleanup);
195-
196-
it('should respond without an error', function () {
197-
expect(callback.args[0][0]).toBe(null);
198-
});
199-
200-
it('should respond with the rendered html', function () {
201-
expect(callback.args[0][1].html).toEqual('Hello, world!!');
202-
});
203-
204-
it('should respond with the correct version', function () {
205-
expect(callback.args[0][1].version).toEqual('1.2.123');
206-
});
207-
});
208-
209161
describe('when getting component returns an error', function () {
210162
var ajaxMock, error;
211163
beforeEach(function (done) {

0 commit comments

Comments
 (0)