为什么这样做:
<p id="emoji">😄</p>
Run Code Online (Sandbox Code Playgroud)
而这不是:
document.getElementById("emoji").innerHTML = String.fromCharCode(parseInt('1f604', 16));
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个websocket客户端 - 服务器应用程序,其中客户端和服务器将在两个不同的实例上运行.
localhost:9006使用angular-fullstack生成器运行,包括socket.iolocalhost:9007使用角度生成器运行+ socket.io-client+ btford.socket-io(AngularJS socket.io桥)
注意:不完整的代码,但我认为相关的部分.
// ----- socketio.js -----
// When the user connects.. perform this
function onConnect(socket) {
// When the client emits 'info', this listens and executes
socket.on('info', function (data) {
console.info('[%s] %s', socket.address, JSON.stringify(data, null, 2));
socket.emit('pong', 'OK!');
});
// Insert sockets below
require('../api/thing/thing.socket').register(socket);
}
socketio.set('origins', 'http://localhost:9007');
// ----- express.js -----
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:9007');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, …Run Code Online (Sandbox Code Playgroud) 在我的多用户AngularJS应用程序中,我的范围内有一个模型对象.用户输入和服务器更新可以操纵此模型.
我有一个$ watch观察员来跟踪模型并更新UI.是否可以从我的$ watch函数中确定我的模型更新的来源/原因?没有这个检查,我有反馈循环的问题(例如UI→服务器→UI).
更新:一些代码
控制器:
$scope.elementProperties = { left: 0 };
$scope.$watch('elementProperties.left', function(newVal, oldVal) { changeSelectedElementProperty('left', newVal, oldVal); } );
Run Code Online (Sandbox Code Playgroud)
指示:
angular.module('myapp.ui-editor').directive('myappPropertiesPanel', function () {
return {
templateUrl: 'views/ui-editor/myappPropertiesPanel.html',
restrict: 'A',
scope: { elementProperties: '=' },
link: function postLink (scope, element, attrs) {
scope.$watch('elementProperties.left', function(newVal, oldVal) { console.log('PropertiesPanel change left', newVal, oldVal); } );
}
};
});
Run Code Online (Sandbox Code Playgroud) 我有一个神秘地解除分配的Objective-C对象(在iOS游戏应用程序中)的问题.
该对象是一个GameCharacter实例,它实例化如下:
for (int c = 0; c < kNrOfGuards; c++) {
GameCharacter* guard = [[GameCharacter alloc] initGuard:self sprite:guardSprite];
[characterArray addObject:guard];
[guard release];
}
Run Code Online (Sandbox Code Playgroud)
我还有一个方便的方法来查找GameCharacter:
- (GameCharacter*)findCharacterWithIndex:(int)index {
return [characterArray objectAtIndex:index];
}
Run Code Online (Sandbox Code Playgroud)
生成错误的代码如下所示:
for (int c = 0; c < [self characterCount]; c++) {
GameCharacter* tempCharacter = [self findCharacterWithIndex:c];
if (tempCharacter.playerId == playerIndex]) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
运行此代码一段时间(从不立即)会在控制台中生成错误:
[GameCharacter playerId]:发送到解除分配的实例0x4e47560的消息
使用NSZombieEnabled技巧,我设法找到导致问题的对象,但我仍然无法理解为什么要解除分配此对象.在我的代码中搜索"release"/"dealloc"不会产生任何线索.
我已经尝试删除"释放"(甚至添加"保留"!)到alloc/init循环(参见顶部),它似乎延长了应用程序可以运行的时间但不能完全解决问题.
任何提示将不胜感激!
编辑
感谢quixoto,Olie,Eiko,tc.,我发现它是我的GameCharacter对象正被释放,但我仍然不明白为什么.以下是反向时间顺序的跟踪日志:
#0 -[GameCharacter dealloc]
#1 objc_setProperty
#2 -[TiledGroundLayer setSelectedCharacter:]
#3 …Run Code Online (Sandbox Code Playgroud) 我正在构建一个具有结构的站点https://[sub.domain.ext]/[language]/articles/[slug],但是它在不同的域(不同的主机名)上会有不同的内容。
一个典型的用例是相同内容的不同语言翻译的不同子域:en.mysite.com、fr.mysite.com 等。
我不想诉诸服务器端渲染使用getServerSideProps(如果内容很少更改,则性能会降低并且不必要)。我可以以某种方式使用getStaticProps/getStaticPaths生成静态站点吗?
这是我当前的siteId = 1硬编码实现:
import React from 'react'
import { useRouter } from 'next/router'
import Page from 'components/page/Page'
import Error from 'components/page/Error'
import ArticleList from 'components/articles/ArticleList'
const { runDatabaseFunction } = require('lib/database')
const { getArticlesForSiteAndLanguage } = require('lib/data/articles')
function ArticleListPage ({ site, articles, error }) {
const { asPath } = useRouter()
const title = 'News'
return (
<Page
title={title}
site={site}
path={asPath}
>
<h1>{title}</h1>
{error && <Error …Run Code Online (Sandbox Code Playgroud) 我终于设法让 Next.js 中的 SSR 与 @apollo/react-hooks 一起工作,但目前我需要用 包装每个页面withApollo,例如:
export default withApollo(IndexPage)
Run Code Online (Sandbox Code Playgroud)
完整来源:https : //github.com/tomsoderlund/nextjs-graphql-hooks-boilerplate/blob/master/pages/articleList.js
如何将withApolloHOC提升到 _app.js 或 _document.js?
我在Meteor中构建了一个简单的实时多人数学游戏,你可以在这里试试:http://mathplay.meteor.com
在本地玩(使用不同的浏览器),一切正常.但是当我和朋友在互联网上玩游戏时,客户经常会失去同步:一个玩家列出的活动问题实际上已经被其他玩家解决了.
我的猜测是,一些应该是仅服务器的代码会在其中一个客户端上执行.有关如何调试此行为的任何建议?
以下是用户提交答案时客户端上发生的情况:
Template.number_input.events[okcancel_events('#answertextbox')] = make_okcancel_handler({
ok: function (text, event) {
question = Questions.findOne({ order_number: Session.get("current_question_order_number") });
if (question.answer == document.getElementById('answertextbox').value) {
console.log('True');
Questions.update(question._id, {$set: {text: question.text.substr(0, question.text.length - 1) + question.answer, player: Session.get("player_name")}});
callGetNewQuestion();
}
else {
console.log('False');
}
document.getElementById('answertextbox').value = "";
document.getElementById('answertextbox').focus();
}
});
Run Code Online (Sandbox Code Playgroud)
callGetNewQuestion()在客户端和服务器上触发:
getNewQuestion: function () {
var nr1 = Math.round(Math.random() * 100);
var nr2 = Math.round(Math.random() * 100);
question_string = nr1 + " + " + nr2 + " = ?"; …Run Code Online (Sandbox Code Playgroud) 我正在编写一个shell脚本(Mac OS X上的Bash)来重命名一堆图像文件.我希望结果如下:
frame_001
frame_002
frame_003
Run Code Online (Sandbox Code Playgroud)
等等
这是我的代码:
let framenr=$[1 + (y * cols * resolutions) + (x * resolutions) + res]
echo $framenr:
let framename=$(printf 'frame_%03d' $framenr)
echo $framename
Run Code Online (Sandbox Code Playgroud)
$framenr看起来是正确的,但$framename总是成为0.为什么?
我有一个基于此模板构建的小型爱好网络应用程序:https ://github.com/tomsoderlund/nextjs-pwa-graphql-sql-boilerplate
\n它使用 ElephantSQL\xe2\x80\x99s 免费层(5 个连接),在 Zeit Now v2 无服务器函数 \xe2\x80\x93 上运行,并不断耗尽 Postgres 连接(\xe2\x80\x9c角色“djsktctf 的连接过多”) “ \xe2\x80\x9d)。
\nI\xe2\x80\x99m 使用deathNPM 关闭连接 - 位于/api/graphql/index.js:
const { ApolloServer, gql } = require(\'apollo-server-micro\')\nconst { config } = require(\'../../config/config\')\n\n// Postgres (pg)\nconst { Pool } = require(\'pg\')\nconst onProcessDeath = require(\'death\')\nconst pool = new Pool({ connectionString: config.databaseUrl })\nlet client\n\nconst initDatabaseClient = async () => {\n if (!client) client = await pool.connect()\n}\ninitDatabaseClient()\n\nonProcessDeath((signal, err) => {\n client && client.release()\n})\n\nconst typeDefs …Run Code Online (Sandbox Code Playgroud) 我有一个基于generator-angular-fullstack. 它在开发模式 ( ) 下工作正常grunt serve,但在生产模式 ( ) 下陷入似乎无限的路由循环grunt serve:dist。
我的服务器控制台输出如下:
Express server running on http://localhost:9000 in production mode
finished populating things
finished populating users
GET / 200 39ms - 1.41kb
GET /views/ui-editor/editor.html 200 15ms - 1.41kb
Run Code Online (Sandbox Code Playgroud)
我的 NodeJS 路由代码如下所示:
module.exports = function(app) {
// Server API Routes
app.get('/api/awesomeThings', api.awesomeThings);
app.post('/api/users', users.create);
app.put('/api/users', users.changePassword);
app.get('/api/users/me', users.me);
app.get('/api/users/:id', users.show);
app.post('/api/session', session.login);
app.del('/api/session', session.logout);
// All other routes to use Angular routing in app/scripts/app.js
// TODO: …Run Code Online (Sandbox Code Playgroud)