Hot Module Replacement with multi entries

The console outputs Ignored an update to unaccepted module error, how to fix it?

log.js:25 Ignored an update to unaccepted module ./src/print.js -> 1
log.js:25 [HMR] The following modules couldn't be hot updated: (They would need a full reload!)
log.js:25 [HMR]  - ./src/print.js

the whole console message is:

log.js:23 [HMR] Waiting for update signal from WDS...
log.js:23 [HMR] Waiting for update signal from WDS...
client?cd17:64 [WDS] Hot Module Replacement enabled.
client?cd17:64 [WDS] Hot Module Replacement enabled.
client?cd17:67 [WDS] App updated. Recompiling...
client?cd17:67 [WDS] App updated. Recompiling...
client?cd17:67 [WDS] App updated. Recompiling...
client?cd17:67 [WDS] App updated. Recompiling...
client?cd17:193 [WDS] App hot update...
log.js:23 [HMR] Checking for updates on the server...
client?cd17:193 [WDS] App hot update...
log.js:23 [HMR] Checking for updates on the server...
log.js:25 Ignored an update to unaccepted module ./src/print.js -> 1
./node_modules/webpack/hot/log.js.module.exports @ log.js:25
onUnaccepted @ only-dev-server.js:25
hotApply @ bootstrap e5893b5…:437
(anonymous) @ only-dev-server.js:20
log.js:25 [HMR] The following modules couldn't be hot updated: (They would need a full reload!)
./node_modules/webpack/hot/log.js.module.exports @ log.js:25
./node_modules/webpack/hot/log-apply-result.js.module.exports @ log-apply-result.js:12
(anonymous) @ only-dev-server.js:39
log.js:25 [HMR]  - ./src/print.js
./node_modules/webpack/hot/log.js.module.exports @ log.js:25
(anonymous) @ log-apply-result.js:14
./node_modules/webpack/hot/log-apply-result.js.module.exports @ log-apply-result.js:13
(anonymous) @ only-dev-server.js:39
log.js:23 [HMR] Nothing hot updated.
log.js:23 [HMR] App is up to date.
index.js:8 Accepting the updated printMe module!
log.js:23 [HMR] Updated modules:
log.js:23 [HMR]  - ./src/print.js
log.js:23 [HMR] App is up to date.

The following is my code:

webpack.config.js:

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const webpack = require('webpack');

module.exports = {
  devtool: 'inline-source-map',
  devServer: {
    contentBase: path.resolve(__dirname, 'dist'),
    hotOnly: true,
  },
  entry: {
    app: './src/index.js',
    print: './src/print.js'
  },
  output: {
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: 'Hot Module Replacement',
      filename: 'index.html',
    }),
    new CleanWebpackPlugin(['dist']),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NamedModulesPlugin(),
  ],
};

./src/index.js:

import _ from 'lodash';
import printMe from './print.js';

if(module.hot) {
  module.hot.accept('./print.js', function() {
    console.log('Accepting the updated printMe module!');

    document.body.removeChild(element);
    element = component();
    document.body.appendChild(element);
  });
}

let element = component();

function component() {
  const element = document.createElement('div');
  const btn = document.createElement('button');

  element.innerHTML = _.join(['Hell', 'webpack'], ' ');

  btn.innerHTML = 'Click me and check the console!';
  btn.onclick = printMe;

  element.appendChild(btn);

  return element;
}

document.body.appendChild(element);

./src/print.js:

export default function printMe() {
  //console.log('I get called from print.js!');
  console.log('Updating print.js...')
}

package.json:

{
  "name": "webpack-demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "webpack",
    "start": "webpack-dev-server --open"
  },
  "keywords": [
    "webpack",
    "demo"
  ],
  "author": "",
  "license": "MIT",
  "dependencies": {
    "lodash": "^4.17.4"
  },
  "devDependencies": {
    "clean-webpack-plugin": "^0.1.16",
    "html-webpack-plugin": "^2.29.0",
    "webpack": "^3.4.1",
    "webpack-dev-server": "^2.6.1"
  }
}

other environment:

  • node v7.4.0
  • npm 4.0.5
  • macOS Sierra 10.12
  • Chrome v59.0.3071.115

please give me help.


Source: stackoverflow-javascript

Vue js – Define prop as a specific type

I’m building a vuejs component which accepts a prop by the name of idFieldType

Now I want this prop to accept only a Number Type or a String Type

So I wrote it as follows

idFieldType: {
    Type: Function,
    default: function() {
        return Number;
    },
    validator: function() {
         if(value == String || value == Number) {
               return true;
         }

         return false;    
    }
}

I also tried replacing the type to Object.

My question is how can I write a prop that accepts only specific types ?


Source: stackoverflow-javascript

Angular 2 – how to update model

I receive data model using a service:

  return this.http.get(queryUrl, opts)   .map((response: Response) => {
    return (<any>response.json()).data.map(el => {
      return new User({
        id: item.id,
        name : item.name
      });
    })   

This gets accesed from component

      makeRequest() {
          this.result = this.myService.loadData()
      }

And passed down as result: Observable<User[]>; to a form, this on Submit sends a post request which gets saved to the backend,all this works. The problem is that my model/website doesn’t get updated this way.

Probably it’s a silly question but, how do I update my model (now after saving to backend the app still holds the old data)? What ar the strategies? Do I have to pass updated data object back to top component and then update?


Source: stackoverflow-javascript

How to disable too many logs of actions-on-google – api.ai

this code is giving me un expected logs, my question is how can i remove these logs then it will be easy for me to point out my own developer log

here is my code:

process.env.DEBUG = 'actions-on-google:*';
import * as admin from 'firebase-admin';
const Assistant = require('actions-on-google').ApiAiAssistant;
import * as functions from 'firebase-functions';
import data from './../../db/index';
import { Request, Response } from "express";
import * as functionRequest from 'request';

// API.AI Action names
const SUBMIT_REPORT = 'submitReport';
const NEXT_QUESTION = 'next_question';

export const webhook = functions.https.onRequest(async (request: Request, response: Response) => {
    const assistant = new Assistant({ request: request, response: response });

    let actionMap = new Map();

    actionMap.set(SUBMIT_REPORT, submitReport);
    actionMap.set(NEXT_QUESTION, next_question);

    assistant.handleRequest(actionMap);

    function submitReport(assistant: any) {

        console.info("user ask for submit report, request body: ", request.body);

        let dataRef = request.body.originalRequest.data.user;
        let userData = {
            groupId: dataRef.groupId,
            subgroupId: dataRef.subgroupId,
            userId: dataRef.userId
        }
        //console.log("userdata: ", userData)
        let botRef = data.db.ref('subgroup-bot-chat-mode/' + userData.groupId + '/' + userData.subgroupId + '/' + userData.userId)
        botRef
            .once('value', function (snapshot) {
                let data = snapshot.val()
                //console.log("here is recieved data: ", data)
                if (data == null) {
                    let entry = {
                        'userAgreed': true,
                        'askedForReport': true,
                        'timestamp': admin.database.ServerValue.TIMESTAMP,
                        'reportIndex': 0,

                    }
                    botRef
                        .set(entry, function (error) {
                            if (!error) {
                                //console.log("Data save successfully at subgroup-bot-chat-mode/")

                                // start asking questions
                                const fullfillment = {
                                    "speech": "qedfqwedf",
                                    "followupEvent": {
                                        "name": "ESOX_WRITE_STANDUP_REPORT_NOW"
                                    },
                                    "contextOut": [
                                        {
                                            "name": "quiz",
                                            "lifespan": 5,
                                            "parameters": {
                                                "index": "0"
                                            }
                                        },
                                        {
                                            "name": "sendReportNow-followup",
                                            "lifespan": 5,
                                        },
                                    ]
                                }
                                response.send(fullfillment);
                                return;
                            }
                        }).catch((e) => {
                            console.error("1. an error occured when getting data from db");
                            response.send({
                                speech: "error on db"
                            })
                            return;
                        })

                } else {
                    response.send({
                        speech: "already"
                    })
                    return;
                }
            }).catch((e) => {
                console.error("2. an error occured when getting data from db");
                response.send({
                    speech: "error on db"
                })
                return;

            })

    }
    function next_question(assistant: any) {

        let dataRef = request.body.originalRequest.data.user;
        let userData = {
            groupId: dataRef.groupId,
            subgroupId: dataRef.subgroupId,
            userId: dataRef.userId
        }

        let questionIndex = request.body.result.contexts[0].parameters.index;
        console.log("index: ", questionIndex);

        // if question index == 0 it means it is first time, we will send first question to user
        // if question index > 0 it means it means user is answered th index
        if (questionIndex == 0) {
            console.log("going to send first question");
        } else if (questionIndex > 0) {
            //todo: process answer here
            console.log("answer: ", request.body.result.parameters.answer);
            let answer = request.body.result.parameters.answer;


            // data.db.ref('subgroup-progress-reports/' + userData.groupId + '/' + userData.subgroupId + '/' + userData.userId + '/' + reportId + '/answers/' + reportIndex)
            //     .set(answer)


        }


        // start asking questions
        functionRequest({
            url: 'https://us-central1-luminous-torch-4640.cloudfunctions.net/getReportQuestions',
            method: 'POST',
            json: {
                'groupId': userData.groupId,
                'subgroupId': userData.subgroupId,
                'userId': userData.userId
            }
        }, function (error, res, body) {
            if (!error && response.statusCode == 200) {
                //console.log("hello: ", res.body)
                switch (res.body.status) {

                    case 'EOF':
                        response.send({
                            "speech": "EOF",
                            "contextOut": [
                                {
                                    "name": "quiz",
                                    "lifespan": 0
                                },
                                {
                                    "name": "sendReportNow-followup",
                                    "lifespan": 0,
                                }
                            ]
                        })
                        break;

                    case 'OK':
                        //sending question back
                        let botRef = data.db.ref('subgroup-bot-chat-mode/' + userData.groupId + '/' + userData.subgroupId + '/' + userData.userId)
                            .update({
                                reportIndex: res.body.reportIndex,
                                reportId: res.body.reportId
                            })

                        response.send({
                            "speech": res.body.question,
                            "contextOut": [
                                {
                                    "name": "quiz",
                                    "lifespan": 5,
                                    "parameters": {
                                        "index": res.body.reportIndex,
                                        "reportId": res.body.reportId
                                    }
                                },
                                {
                                    "name": "sendReportNow-followup",
                                    "lifespan": 5,
                                }
                            ]
                        })

                        break;
                    case 'ALREADY_ASKED_FOR_TODAY':
                        response.send({
                            "speech": "you are already submited the report for today",
                            "contextOut": [
                                {
                                    "name": "quiz",
                                    "lifespan": 0
                                },
                                {
                                    "name": "sendReportNow-followup",
                                    "lifespan": 0,
                                }
                            ]
                        })
                        break;
                    default:
                        console.error("Unknown case");
                        //http request failed
                        response.send({
                            "speech": "Something went wront on question server",
                            "contextOut": [
                                {
                                    "name": "quiz",
                                    "lifespan": 0
                                },
                                {
                                    "name": "sendReportNow-followup",
                                    "lifespan": 0,
                                }
                            ]
                        })
                        return;
                }
            } else {
                //http request failed
                response.send({
                    "speech": "Something went wront on question server",
                    "contextOut": [
                        {
                            "name": "quiz",
                            "lifespan": 0
                        },
                        {
                            "name": "sendReportNow-followup",
                            "lifespan": 0,
                        }
                    ]
                })
            }
        })
    }

})//end of webhook http trigger

logs of firebase functions are here:

2:10:34.707 PM info webhook Sat, 05 Aug 2017 09:10:34 GMT
actions-on-google:debug map of intents
2:10:34.707 PM info webhook Sat, 05 Aug 2017 09:10:34 GMT
actions-on-google:debug name=next_question 2:10:34.707 PM info
webhook Sat, 05 Aug 2017 09:10:34 GMT actions-on-google:debug key is
id 2:10:34.706 PM info webhook Sat, 05 Aug 2017 09:10:34 GMT
actions-on-google:debug name=submitReport 2:10:34.706 PM info webhook
Sat, 05 Aug 2017 09:10:34 GMT actions-on-google:debug key is id
2:10:34.706 PM info webhook Sat, 05 Aug 2017 09:10:34 GMT
actions-on-google:debug invokeIntentHandler_: handler=[object Map],
intent=next_question


Source: stackoverflow-javascript

Why reading undeclared variable gives reference error but undeclared object property returns undefined in javascript?

In below code, if I print this.property2 on console, JS engine prints undefined, if I replace the statement to print only property2 compiler
throws a reference error
if I declare the variable property2 then the compiler will return undefined.

function foo() {
  var property;
  console.log(this.property2)
  console.log(this.property2 === property2)
  console.log(property2)
}

foo.property="property value";
var property2; // modified to resolve reference error
foo();
console.log(foo.property);

As I have shown in the code this.property2 is equal to property2 so why javascript behaves differently for the same variable.

Coming to my question are both variables different? (this.property2 and property2) if they are different why the comparison returns true?
and if they are not different then why I have to declare property2 to get the return value and this.property2 returns values without
declaration.

am I missing anything?


Source: stackoverflow-javascript

Countdown until date with jpeg/svgs

I would love to make/use a javascript which counts down until a certain date.

(example: the 1th of sept)

What should it do?

This script should delete an image jpeg or svg (10px x 10px) daily. So the script should have the amount of days in pictures left.

(example: 29 days left so 29 pictures on the website, tomorrow 28 pictures, day after 27 pictures)


Does anyone know a code that would allow this kind of a “daily update” to happen automatically?
Any help would be very much appreciated!


Source: stackoverflow-javascript

Limit camera rotation on the Y axis

I am using JSModeler to display OBJ files. It internally uses THREE.JS and creates a PerspectiveCamera. What I need is to limit the movement of the camera on the Y axis so not to go underneath the object. I know how to do this with THREE.OrbitControls but this doesn’t work with JSModeler. Is there a way to directly control the camera movement? Thanks.


Source: stackoverflow-javascript

Reactjs function firing twice?

Hi i try to learn Reactjs, and want to do a simple Caeser-En/Decryption (shifting characters).

It works fine when the Inputtext is changeing, but it seems that if the encryption-key is changeing (updateRot()), the CaeserShift-function fires twice (or even more often?).

But i can’t figure out what i’m doing wrong.

class MarkdownEditor extends React.Component {
  constructor(props) {
    super(props);
    this.handleChange = this.handleChange.bind(this);
    this.updateRot = this.updateRot.bind(this);
    this.state = {value: 'abcdefghijklmnopqrstuvwxyz',
                  rot: 1
                 };
  }
  
  updateRot(e){
    this.setState({
      rot: e.target.value      
    });
  }
  
  handleChange(e){
    this.setState({
      value: e.target.value
      });
  }

caesarShift(str, amount){

	var output = '';
	// Go through each character
	for (var i = 0; i < str.length; i ++) {

		// Get the character we'll be appending
		var c = str[i];

		// If it's a letter...
		if (c.match(/[a-z]/i)) {

			// Get its code
			var code = str.charCodeAt(i);
			// Uppercase letters
			if ((code >= 65) && (code <= 90))
				c = String.fromCharCode(((code - 65 + amount) % 26) + 65);

			// Lowercase letters
			else if ((code >= 97) && (code <= 122))
				c = String.fromCharCode(((code - 97 + amount) % 26) + 97);
     
		}
		// Append
		output += c;
	}
	// All done!
  return output
    
};

  render() {
    return (
      

Input