我正在构建一个角度2应用程序(使用Firebase API).我正在使用AngularFire模块.我想知道如何将canActivate方法与AngularFire auth Observable混合,我发现了这篇文章.答案是让canActivate方法返回一个Observable<boolean>:
canActivate(): Observable<boolean> {
return this.auth
.take(1)
.map((authState: FirebaseAuthState) => !!authState)
.do(authenticated => {
if (!authenticated) this.router.navigate(['/login']);
});
}
Run Code Online (Sandbox Code Playgroud)
这是我第一次看到Observable do操作符,我无法理解它的真正含义?官方文件没有帮助我,我没有找到合适的例子.
有人可以带一些.do()使用示例吗?与.subscribe()?有区别?
我有一个HospitalComponent试图显示医院列表的组件.它使用的readAll方法HospitalService(从firebase返回一个Observable):
ngOnInit() {
this.hospitalService
.readAll() // Make a firebase call
.subscribe(hospitals => this.hospitals = hospitals);
}
Run Code Online (Sandbox Code Playgroud)
路由/hospital已插入此组件HospitalComponent.每次我到达时/hospital,Angular 2都会创建一个新的HospitalComponent,并且新的呼叫将被发送给hospitalService.
每次到达时/hospital,医院名单都会延迟显示.
从服务构造函数本身检索医院列表是一种好习惯吗?这样,我可以从后台管理刷新列表,而不是有一些延迟.我会在组件中:
ngOnInit() {
this.hospitals = this.hospitalService.readAll();
}
Run Code Online (Sandbox Code Playgroud)
并在服务中:
constructor(private hospitalService: HospitalService) {
hospitalService.subscribe(hospitals => this.hospitals = hospitals);
}
Run Code Online (Sandbox Code Playgroud)
但这意味着要手动管理所有医院的变化.
我刚开始在我的React项目中添加TypeScript,我无法弄清楚这个错误:
import {Link} from 'react-router';
Module '"/Users/.../node_modules/@types/react-router/index"' has no exported member 'Link'.
Run Code Online (Sandbox Code Playgroud)
该Link组件存在于react-router(代码正在运行)中,但TypeScript无法识别它.我添加了@types/react-router,似乎没有实现Link.有任何想法吗 ?
摘自我的package.json:
"@types/react": "^15.0.25",
"@types/react-dom": "^15.5.0",
"@types/react-router": "^4.0.11",
"@types/reactstrap": "^4.3.4",
...
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-router": "^3.0.2",
"reactstrap": "^4.2.0"
...
"typescript": "^2.3.3",
Run Code Online (Sandbox Code Playgroud) 我使用Stack 工具创建了一个 Haskell CLI 。感谢 Travis,我刚刚成功设置了交叉编译,但我不明白为什么 linux (6MB)、osx (2MB) 和 windows (18MB!) 之间的可执行文件大小如此不同。怎么来的?
发布:https : //github.com/unfog-io/unfog-cli/releases/tag/v0.1.2
特拉维斯 conf:https : //github.com/unfog-io/unfog-cli/blob/master/.travis.yml
编辑
当我用 tar.gz 压缩可执行文件时,我减少了差异,但仍然如此!我现在有 linux (1.35MB)、osx (0.61MB)、windows (3.93MB)(见发布)
我有一个 PIN 码字段组件,它只是包装在React.Fragment. 每次按下一个键,它都会聚焦下一个输入。当我到达最后一个输入时,我想触发一个表格来聚焦组件之外的下一个控制器(输入、按钮、链接等)。我尝试发送 a KeyboardEvent,但不起作用:
const evt = new KeyboardEvent("keydown", {
...
code: "Tab",
key: "Tab",
})
lastInput.dispatchEvent(evt)
Run Code Online (Sandbox Code Playgroud)
任何想法?
源代码: https: //github.com/soywod/react-pin-field
演示:https://react-pin-field.soywod.me/
我有一个使用 Express 的 Node 应用程序,我尝试为我的客户端设置 cookie。它在本地环境(http)上运行良好。但是一旦我投入生产(https),我就很好地收到了cookie(我可以在响应中看到它),但它没有设置。任何想法?
Nginx 配置:
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
server {
listen 443 ssl default_server;
listen [::]:443 default_server;
server_name back.domain.com;
ssl_certificate /etc/letsencrypt/.../fullchain.pem;
ssl_certificate_key /etc/letsencrypt/.../privkey.pem;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
}
}
Run Code Online (Sandbox Code Playgroud)
节点应用程序:
const api = express()
api.enable('trust proxy')
api.use(cors({origin: 'https://front.domain.com', credentials: true}))
api.post('/login', (req, res) => …Run Code Online (Sandbox Code Playgroud) 我有一个 Next.js 博客,只有 2 个路由:/和/posts/:slug.
当我打开时/posts/my-post-title,我点击返回链接(到/),一切都很好。页面加载速度快(无刷新)。
当我打开/并单击 时/posts/my-post-title,页面会刷新,但我不知道为什么。有什么建议吗?
我有一段代码可以Textbox这样创建一个新的:
new fabric.Textbox('Ajouter du texte')
Run Code Online (Sandbox Code Playgroud)
问题是文本框与其内容相比太小:
如果我设置固定宽度,我会得到一些填充:
new fabric.Textbox('Ajouter du texte', {width: 350})
Run Code Online (Sandbox Code Playgroud)
如何调整文本框大小以匹配文本选择大小?我找不到有关如何获取选择尺寸的任何信息。
我用的是布料版4.0.0-beta.5。
我正在尝试为我的django项目注册服务工作者.这是我用于注册的代码:
<!-- register service worker -->
<script type="text/javascript">
if('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register("{% url 'sw.js' %}").then(function(registration) {
console.log("Service worker registered.");
console.log("Registered at: "+registration.scope);
});
});
}
</script>
Run Code Online (Sandbox Code Playgroud)
这是我的service_worker.js中的代码:
// App install banner
window.addEventListener('beforeinstallprompt', function(e) {
e.userChoice.then(function(choiceResult) {
console.log(choiceResult.outcome);
if(choiceResult.outcome == 'dismissed') {
console.log('User cancelled home screen install');
} else {
console.log('User added to home screen');
}
});
});
Run Code Online (Sandbox Code Playgroud)
我在控制台中看到此错误:"未捕获的ReferenceError:窗口未定义"
如何解决这个问题?
我正在使用ReadP模块编写一个小型解析器。我有这样的表达:
cmdExpr = string "create" <|> string "add" <|> string "another alias" <|> ...
Run Code Online (Sandbox Code Playgroud)
我想抽象出<|>操作,但我不知道如何。类似的东西intercalate:
getExpr cmds = intercalateM (<|>) $ map string cmds
cmdExpr = getExpr ["create", "add", "another alias", ...]
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
javascript ×5
reactjs ×3
angular ×2
angularfire2 ×2
firebase ×2
haskell ×2
observable ×2
rxjs ×2
typescript ×2
cookies ×1
django ×1
ecmascript-6 ×1
events ×1
executable ×1
express ×1
fabricjs ×1
keyboard ×1
monads ×1
next.js ×1
nginx ×1
node.js ×1
parsing ×1
react-router ×1
refresh ×1
travis-ci ×1