小编Jus*_*ltz的帖子

动态包.json

我正在开发一个 nodejs 项目,它在 GitHub 中有多个私有依赖项package.json,如下所示:

"dependencies" : {
   "mymodule":"git+https://<token>:xoauthbasic@github.com/my_github_account/my_repo.git#<commit-ish>"
}
Run Code Online (Sandbox Code Playgroud)

我在这里有两个问题:

  1. package.json为了安全起见,我不希望将 oAuth 令牌与我的文件分开。
  2. 我希望我用于依赖项的分支依赖于它内置的环境。例如:在生产环境中,使用 #master,在开发环境中,使用 #development。

这些问题有什么解决办法吗?此外,如果解决方案适用于 Heroku,那就太好了。

javascript json heroku node.js npm

8
推荐指数
0
解决办法
1537
查看次数

React-JS:通过HOC包装器访问子方法

我有一个Editor看起来像这样的组件:

class EditorComp extends Component {
  focus() {
    this.refs.input.focus();
  }

  render() {
    return (
      <input 
        ref="input"
        ...
      />
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

因此,使用的元素EditorComp可以设置ref并调用其focus方法并将焦点应用于较低级别的输入,如下所示:

class Parent extends Component {
  render() {
    return (
      <div>
        <button onClick={() => this.refs.editor.focus()}>Focus</button>
        <EditorComp ref="editor" />
      </div>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

然而,当包装EditorComp在高阶组件(如react-reduxs connect())中时,EditorComp失去焦点方法,因为它被困在HOC下面.

例:

const WrappedEditor = connect()(EditorComp); // react-redux's connect, for example
const wrappedEditorInstance = <WrappedEditor />;

wrappedEditorInstance.focus() // Error! Focus is not a …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs redux react-redux

8
推荐指数
1
解决办法
2113
查看次数

使用express中间件时结合socket和express?

有没有办法在快速中间件中获取请求的套接字?

IE:

import express from 'express';
import io from 'socket.io';

const app = express();

// combine app and io somehow ...

// When client makes a GET request to '/emit/to/self', that client's socket will recieve the 'hello:world' message.
app.get('/emit/to/self', (req, res) => {
  req.socket.emit('hello:world', { ... });
  res.send('You just triggered your own socket!')
})
Run Code Online (Sandbox Code Playgroud)

这个想法是 express 中间件具有req.socket引用来自同一客户端的连接套接字的属性。这将允许一些更复杂的用例,例如:

app.post('/image/create', (req, res) => {
  createExpensiveImage({
    onProgress: (progress) => { req.socket.emit('image:progress', { progress }) },
  });
})
Run Code Online (Sandbox Code Playgroud)

客户端将拥有他们刚刚请求通过 API 创建的图像的准确进度条。

javascript sockets node.js express socket.io

6
推荐指数
1
解决办法
4948
查看次数

标签 统计

javascript ×3

node.js ×2

express ×1

heroku ×1

json ×1

npm ×1

react-redux ×1

reactjs ×1

redux ×1

socket.io ×1

sockets ×1