Ember.JS : 'serializer.get is not a function' - serialization

So i'm learning EMBER JS from codeschool and i sometime like to save my current progress into my computer. Everything went nice and smoothly until we started to see Array Controller ( and by nice and smoothly i mean everything was working fine, as it does on codeschool ). Since then i got this error :
Error while processing route: index serializer.get is not a function TypeError: serializer.get is not a function
at ember$data$lib$system$store$serializer$response$$normalizeResponseHelper (http://localhost:63342/Cours/EmberJS/Flint/js/vendors/ember-data.js:5696:24)
at http://localhost:63342/Cours/EmberJS/Flint/js/vendors/ember-data.js:7450:31
at Object.Backburner.run (http://localhost:63342/Cours/EmberJS/Flint/js/vendors/ember.js:222:25)
at ember$data$lib$system$store$$Service.extend._adapterRun (http://localhost:63342/Cours/EmberJS/Flint/js/vendors/ember-data.js:13030:37)
at http://localhost:63342/Cours/EmberJS/Flint/js/vendors/ember-data.js:7449:19
at tryCatch (http://localhost:63342/Cours/EmberJS/Flint/js/vendors/ember.js:54770:14)
at invokeCallback (http://localhost:63342/Cours/EmberJS/Flint/js/vendors/ember.js:54785:15)
at publish (http://localhost:63342/Cours/EmberJS/Flint/js/vendors/ember.js:54753:9)
at http://localhost:63342/Cours/EmberJS/Flint/js/vendors/ember.js:31568:7
at Queue.invoke (http://localhost:63342/Cours/EmberJS/Flint/js/vendors/ember.js:901:16)
So i thought, somehow, my ember.js or ember-data.js was the culprit but nay, it's not ( im up-to-date ). I think the bug is somewhere located in the way i initialize my Route ( eventho i copy/pasted the content of my local files from those on codeschool who works perfectly ) and according to the error message, i think the index route is responsible so here is my router map :
App.Router.map(function() {
this.route('credits', { path: '/thanks' });
this.resource('products', function() {
this.resource('product', { path: '/:product_id' });
});
this.resource('contacts', function() {
this.resource('contact', { path: '/:contact_id' });
});
});
And here's my route ( they're all made like this one, except that i sometime search in 'contact' rather than 'product' )
App.IndexRoute = Ember.Route.extend({
model: function(){
return this.store.findAll('product');
}
});
We also use the fixture adapter so it might come from this too :
App.ApplicationAdapter = DS.FixtureAdapter.extend({});
Does anybody ever got this bug about the serializer ? Thank you'all in advance !

I believe this is due to the removal of the Fixture Adapter in a recent ember-data release. I'm just learning ember myself, but I was finally able to get rid of this error using a combination of reverting to a slightly older ember-data version and installing the replacement Fixture Adapter addon.
In your application dir, update the ember-data line in both bower.json and package.json to:
"ember-data": "1.0.0-beta.19.2",
and in package.json add this line after the ember-data one:
"ember-data-fixture-adapter": "^1.0.0",
Delete the bower_components and node_modules dirs in your application, and then run npm install and bower install from your application's home dir.

Related

PWA InjectManifest workbox console / debug output suddenly disabled (Vue.js / Quasar Framework)

I'm building a PWA with Vue.js / Quasar Framework and recently added the PWA capability. I changed the "workboxPluginMode" property to "InjectManifest" and at first Workbox gave me debug / console as expected.
Also, the "custom-service-worker.js" definetly gets picked up by the process because it displays an error when i remove this line:
precacheAndRoute(self.__WB_MANIFEST)
So the file is recognized and actively using the defined caching strategies (i think), but it won't provide me any debug info or console.log's on console anymore. I really don't know what i have changed to do that.
My "custom-service-worker.js" looks like this:
import { precacheAndRoute } from 'workbox-precaching'
import { registerRoute } from 'workbox-routing'
import { StaleWhileRevalidate } from 'workbox-strategies'
console.log('custom service worker active')
// Use with precache injection
precacheAndRoute(self.__WB_MANIFEST)
// Caching strategies
registerRoute(
({url}) => {
console.log(url)
// url.pathname.startsWith('/images')
},
new StaleWhileRevalidate()
);
self.addEventListener('fetch', function(event) {
console.log(event)
event.respondWith(fetch(event.request));
})
I have no clue why, but the console debug output of workbox was only displayed in my default browser (Vivaldi). I wanted to work on plain Chromium because I couldn't install my PWA with Vivaldi (no installation prompt popped up), but that also works now. Have literally no explanation for this, but this is PWA development I guess, it is what it is. Anyways, problem solved for me.

Vuex Action never resolve

I'm having problem to make my Action resolve the promise.
I've read what looks like the most relevant posts.
Returning Promises from Vuex actions
I want to know when my action is finished, then my component can start doing other stuff.
The problem is, the Action never returns the Promise.
myComponent.vue
methods: {
loadUrls() {
this.$store.dispatch('getUrls').then(result => {
console.log("getUrls result", result)
})
},
vuex.js
actions: {
getUrls() {
console.log("getUrls")
return new Promise((resolve) => {
setTimeout(() => {
console.log("setTimeout in")
resolve("Resolved!")
}, 1000)
})
},
That's my console log:
I've used the "setTimeout" to make as simple as possible the problem. In real life I call an API.
I do not need to rely on the result of this promise. I'm aware about it. I use Vuex as the source of truth, but I need to track when the event in completed.
Thanks in advance =)
SOLVED! It worked after I delete my dist Folder, close VSCode and open a new Chrome instance using the new build local host URL.
Thanks #User-28. I saw his shared code and realised nothing was wrong with my code. Then I start looking at my environment.
My very first code didn't have Promise Resolve in the action. I compiled and I was testing it.
Then I found Returning Promises from Vuex actions which explained how to use the Promise in it. I compiled and I was TRYING to test it. Never success. Somehow the code without the Promise was always there. After clean up Dist folder, Close VS code and use a new Chrome instance, the new code was in place and worked.
I'm still don't know the actual problem, but at least it can keep going forward now.

I'm trying to use react-call-detection to detect a missed call number but something is not working

Hey there to everyone!
I'm posting my first question so I'll try to be as clear as possible!
I'm building a native android app using react-native(0.61.5), I'm using setState hook instead of the classic state and I want to use the react-native-call-detection library(1.8.2).
What is the problem?
function startListenerTapped() {
console.log('start');
callDetector = new CallDetectorManager((event, number) => {
console.log(event);
console.log('inside call detector');
if (event === 'Missed') {
console.log(event);
console.log(number);
setMissedCaller(number);
}
},
true,
() => { console.error('access denied') },
{
title: 'Phone State Permission',
message: 'This app needs access to your phone state in order to react and/or to adapt to incoming calls.'
}
)
}
I run this function when my component mounts, callDetector is set as undefined, I get the 'start' log but when I simulate a call on my AVD nothing happens.
From what I understood the CallDetectorManager works like an event listener, right?
Or do I need to start it every time a call happens?
Another thing I've had a problem with was when I was trying to run a build for the app. I have Gradle 6.0 and I had an error with the react-native-call-detection:
Attribute application#allowBackup value=(false) from AndroidManifest.xml:13:7-34
is also present at [:react-native-call-detection] AndroidManifest.xml:21:9-35 value=(true).
Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at
AndroidManifest.xml:7:5-117 to override.
I couldn't really understand what this meant, and the only thing that I've found that solved it was to create a react-native.config.js file with this line of code in it:
module.exports = { dependencies: { 'react-native-call-detection': { platforms: { android: null, }, }, }, };
Another thing that I've only noticed now is that I have a problem with the module of the library.
Could not find a declaration file for module 'react-native-call-detection'.
'c:/folders/projectName/node_modules/react-native-call-detection/index.js' implicitly has an 'any' type.
Try `npm install #types/react-native-call-detection` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-native-call-detection';`
Does anybody knows what that means?!
I think I start to think that it means that I need to find an alternative to this library... AHAHA!
Any kind of help or solution would be more than welcome!
Thanks in advance for everything!

gulp-durandal TypeError: req.toUrl is not a function

I try to implement gulp to my durandal project as explain on Durandal gulp doc
main.js file is successfully build, but when trying to click something that will open a modal dialog, it will show this error (firefox):
TypeError: req.toUrl is not a function
url = req.toUrl(nonStripName),
main.js (line 48306, col 16)
here my configuration on gulpfile.js
var gulp = require('gulp');
var durandal = require('gulp-durandal');
gulp.task('default', function(cb)
{
durandal({
baseDir: 'public_html/app',
main: 'main.js',
output: 'main.js',
almond: true,
minify: false
})
.on('error', function(err) {
console.error('error. ' + err);
})
.pipe(gulp.dest('public_html/build'))
.on('end', cb);
});
I'm also came across with this answer https://stackoverflow.com/a/23329383/1889014
But i'm not sure if this is related to my issue.
Can someone please help or guide me through this ? Thanks!
I also had this issue using gulp, Durandal and modal dialogs. Adding a getView function to the viewmodel that returns the url for the view fixes it.
eg
function getView() {
return "views/theView.html";
}
I am sure there must be a better way of solving this problem but this seems to work in the few places I have needed it.
I have experienced this error due to writing the view name using the wrong case. E.g. if the file is called myView.html but you require 'MyView'.
I am not building using gulp-durandal because it's giving very odd errors, and requirejs is working much better directly. I fixed this error by including all views manually in my requirejs build config.
include: [
'text!customWidgets/alertsSection/title.html', //custom
'text!customWidgets/alertsSection/body.html', //custom
'text!customWidgets/exclusions/body.html', //custom
'text!customWidgets/exclusions/title.html', //custom
'text!customWidgets/submit/body.html', //custom
'text!customWidgets/submit/title.html', //custom
]
There are many more files in my include due to the nature of durandal and the dynamic loading of views... but I don't want to spam everyone :)

"undefined is not a function" error when using mongoose-sessions and express

When I init the application everything is ok, but when I go to any page
like "localhost/" I get this (double: once for the index.html and once for the javascript requested, see bellow) error:
TypeError: undefined is not a function
at hash (myapp\node_modules\express\node_modules\connect\lib\middleware\session.js:341:10)
at myapp\node_modules\express\node_modules\connect\lib\middleware\session.js:324:24
at Promise.module.exports.SessionStore.get (myapp\node_modules\session-mongoose\index.js:85:22)
at Promise.addBack (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\promise.js:128:8)
at Promise.EventEmitter.emit (events.js:96:17)
at Promise.emit (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\promise.js:66:38)
at Promise.complete (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\promise.js:77:20)
at Query.findOne (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\query.js:1607:15)
at model.Document.init (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\document.js:229:11)
at model.init (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\model.js:196:36)
TypeError: undefined is not a function
at hash (myapp\node_modules\express\node_modules\connect\lib\middleware\session.js:341:10)
at myapp\node_modules\express\node_modules\connect\lib\middleware\session.js:324:24
at Promise.module.exports.SessionStore.get (myapp\node_modules\session-mongoose\index.js:85:22)
at Promise.addBack (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\promise.js:128:8)
at Promise.EventEmitter.emit (events.js:96:17)
at Promise.emit (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\promise.js:66:38)
at Promise.complete (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\promise.js:77:20)
at Query.findOne (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\query.js:1607:15)
at model.Document.init (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\document.js:229:11)
at model.init (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\model.js:196:36)
This is the code I'm using:
var express = require('express');
var app = this.__app = express();
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({
store: this.__getSessionStore()
,secret: this.__secretSession
}));
app.post('/rpc', this.__manageRequest.bind(this)); // <-- this method is not even called
app.use("/client", express.static('./client/')); //
// gets the index.html, but files in subfolders (which exists) throws the second error in the double error
app.use("/", express.static('./client/production/build'));
app.listen(this.__appPort, this.__appIp);
How I get the session store:
__getSessionStore: function(){
var express = require('express');
var app = this.__app;
var SessionMongoose = require("session-mongoose")(express);
var mongooseSessionStore = new SessionMongoose({
url: this.__mongodbUrl
,interval: 120000
});
return mongooseSessionStore;
}
Express version: 3.0.0
Mongoose-sessions version: 0.2.0
The undefined method is "crc16" in the hash method: in debug is undefined too
function hash(sess) {
return crc16(JSON.stringify(sess, function(key, val){
if ('cookie' != key) return val;
}));
}
In the crc module, there is a if(window) and window is defined, the problem is that I cannot see where it's defined!
Because of this window, it will not export any of the modules and therefore the function is undefined! I just very hackly removed the if(window) to always export to it's module.
Well, that was a bug in the crc#0.2.0 module (https://github.com/alexgorbatchev/node-crc/pull/10), and the express is requiring that exact version.
What exactly is the problem and how to fix it?
thanks a lot
This only worked the first time, then BUM, same error again...
As the dependencies in the session-mongoose are like this (loosely):
"dependencies": {
"mongoose": ">= 3.0"
},
It downloaded the mongoose 3.5.4! Npm should only have downloaded the 3.0, but I don't know what happened.
Now I deleted that and put the mongoose at the same version as in my app: 3.4.0.
I still don't know what's wrong with the 3.5.4 version or if the problem is not being equal, but here is the fix.
So many time lost because of this... :S
Perhaps edit ./node_modules/express/package.json to tell it to use more recent CRC library.
Change the line:
"crc": "0.2.0",
to
"crc": ">= 0.2.0",
and then run
npm install -d
If that doesn't install an updated crc library, manually delete the folder ./node_modules/express/node_modules/crc and try again.
I don't promise this will work but it is worth a shot!