Last active
October 30, 2020 13:30
-
-
Save grayt0r/d5d0c5b4b79815305ad427fdf7ff04f2 to your computer and use it in GitHub Desktop.
pushPayload issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from 'ember-data/model'; | |
import attr from 'ember-data/attr'; | |
export default class extends Model { | |
@attr name; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Route from '@ember/routing/route'; | |
const fooJson = { | |
foo: { | |
id: 1, | |
name: "One" | |
}, | |
_foos: [{ | |
id: 2, | |
name: "Two" | |
}] | |
}; | |
const server = new Pretender(); | |
server.map(function() { | |
this.get('/foos/1', function() { | |
return [200, {}, JSON.stringify(fooJson)]; | |
}); | |
}); | |
export default class ApplicationRoute extends Route { | |
async model() { | |
// Swap these lines to see the difference in behaviour | |
this.store.pushPayload('foo', fooJson); | |
// this.store.findRecord('foo', 1); | |
return this.store.peekAll('foo'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RESTSerializer from '@ember-data/serializer/rest'; | |
export default class ApplicationSerializer extends RESTSerializer { | |
normalize() { | |
console.log('***** normalize'); | |
return super.normalize(...arguments); | |
} | |
normalizeResponse() { | |
console.log('***** normalizeResponse'); | |
return super.normalizeResponse(...arguments); | |
} | |
modelNameFromPayloadKey(payloadKey) { | |
console.log('***** modelNameFromPayloadKey', payloadKey); | |
if (payloadKey.charAt(0) === '_') { | |
// Uncommenting this line fixes the problem | |
// payloadKey = payloadKey.substr(1); | |
} | |
return super.modelNameFromPayloadKey(payloadKey); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.17.1", | |
"EmberENV": { | |
"LOG_VERSION": false, | |
"EXTEND_PROTOTYPES": false, | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"ember": "3.18.1", | |
"ember-template-compiler": "3.18.1", | |
"ember-testing": "3.18.1", | |
"pretender": "https://unpkg.com/[email protected]/dist/pretender.bundle.js" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0", | |
"ember-data": "3.18.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment