小编Dra*_*anS的帖子

画布中的矩形尺寸错误

我正在实施一个颜色选择器.渲染有问题.当我调用c.fillRect(0, 0, 100, 80);该矩形的大小是103x42 px而不是100x80.这有什么不对?

此外,矩形是抗锯齿的.我是否需要将位置偏移(0.5,0.5)以避免AA?我没有使用任何类型的坐标系转换.

colorSlider = function($e, color) {
    this._$canvas = $('<canvas></canvas>');
    this._c = this._$canvas[0].getContext('2d');
    this._color = color || { r: 0, g: 0, b: 0 };
    this._$canvas.width('310px');
    this._$canvas.height('80px');
    $e.append(this._$canvas);
    this._render();
    var me = this;
    this._$canvas.mousedown(function(e) { me._mouseDown.call(me, e) });
    this._$canvas.mouseup(function(e) { me._mouseUp.call(me, e) });
    this._$canvas.mousemove(function(e) { me._mouseMove.call(me, e) });
    this._dragChannel = 0;
}

colorSlider.prototype._pointInRect = function(x, y, rect) {
    return x >= rect.x && x <= rect.x + rect.w && y >= rect.y && y …
Run Code Online (Sandbox Code Playgroud)

html5 2d canvas

9
推荐指数
1
解决办法
4916
查看次数

AngularJS - valueFn

什么是功能

function valueFn(value) {return function() {return value;};}
Run Code Online (Sandbox Code Playgroud)

在angular.js中定义.

它用于前.在

var lowercaseFilter = valueFn(lowercase);
register('lowercase', lowercaseFilter);
Run Code Online (Sandbox Code Playgroud)

如果我们直接使用小写,那么会有什么不同

register('lowercase', lowercase);
Run Code Online (Sandbox Code Playgroud)

而不是前一行.

同样的方法,在方法中

function ngDirective(directive) {
  if (isFunction(directive)) {
    directive = {
      link: directive
    }
  }
  directive.restrict = directive.restrict || 'AC';
  return valueFn(directive);
}
Run Code Online (Sandbox Code Playgroud)

为什么最后一行不是

return directive;
Run Code Online (Sandbox Code Playgroud)

return valueFn(directive);
Run Code Online (Sandbox Code Playgroud)

javascript oop angularjs

5
推荐指数
1
解决办法
1095
查看次数

表达评估2次

在以下示例中:

的test.html

<!DOCTYPE html>
<html ng-app ng-controller="AppController">
    <head>
        <script type="text/javascript"  src="angular.js"></script>
        <script type="text/javascript"  src="script1.js"></script>
    </head>
    <body>
        <div ng-include="'test1.html'"></div>
        {{testFn()}}
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

test1.html

<div>{{testFn()}}</div>
Run Code Online (Sandbox Code Playgroud)

script1.js

function AppController($scope) {
    $scope.testFn = function() {
        console.log("TestFn");
        return "test";
    }
}
Run Code Online (Sandbox Code Playgroud)

发生fn testFn执行4次.我希望在控制台中只看到2个日志.甚至,如果我删除

<div ng-include="'test1.html'"></div>
Run Code Online (Sandbox Code Playgroud)

有2个日志,而不仅仅是一个.我错了什么?

更新:

angular.js

// added console.log to original code
var ngBindDirective = ngDirective(function(scope, element, attr) {
  console.log("ngDirective", attr.ngBind);
  element.addClass('ng-binding').data('$binding', attr.ngBind);
  scope.$watch(attr.ngBind, function ngBindWatchAction(value) {
    console.log("ngDirective - scope.$watch", value);
    element.text(value == undefined ? '' : value);
  });
});
Run Code Online (Sandbox Code Playgroud)

的test.html

<!DOCTYPE html> …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs

5
推荐指数
1
解决办法
993
查看次数

如何为传奇提供历史实例?

我想在成功登录后重定向到新页面.路线(V4)使用如下:

import { browserHistory } from '....browser_history_signleton';
...

class App extends Component {
  render() {
    const { authentication: { isSignedIn } } = this.props;
    return (
      <ConnectedRouter history={browserHistory}>
        <div>
          <Header/>
          <Route exact path="/" component={Home}/>
          <PrivateRoute isAuthorized={isSignedIn} path="/page1" component={PageOne}/>
          <PrivateRoute isAuthorized={isSignedIn} path="/page2" component={PageTwo}/>
        </div>
      </ConnectedRouter>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

传奇看起来像:

import { browserHistory } from '....browser_history_signleton';

export function* loginSaga() {
  while (true) { // eslint-disable-line no-constant-condition
    try {
      const payload = yield take(LOGIN_SUBMIT);
      const raceResult = yield race({
        signin: call(loginRequest, payload),
        logout: …
Run Code Online (Sandbox Code Playgroud)

redux-saga react-router-redux react-router-v4

5
推荐指数
1
解决办法
1037
查看次数

从手写JavaScript调用GWT方法

我想从浏览器控制台执行一些js方法来调用gwt代码.对于前者

showMyWindow();

JS:

function showMyWindow() {
// call gwt code from here MyWindow::showMe()
}
Run Code Online (Sandbox Code Playgroud)

GWT:

class MyWindow extends Window {
  public static showMe {
    MyWindow wnd = new MyWindow();
    wnd.show();
  }
}
Run Code Online (Sandbox Code Playgroud)

怎么做?谢谢.

javascript gwt jsni

3
推荐指数
1
解决办法
1996
查看次数

React Isomorphic Rendering - 处理窗口调整大小事件

我想根据浏览器窗口的当前大小设置组件的状态.已使用服务器端呈现(React + Redux).我正在考虑使用Redux商店作为粘合剂 - 只是在调整大小时更新商店.有没有其他/更好的解决方案,不涉及Redux.谢谢.

class FocalImage extends Component {

  // won't work - the backend rendering is used
  // componentDidMount() {
  //  window.addEventListener(...);
  //}

  //componentWillUnmount() {
  //  window.removeEventListener('resize' ....);
  //}

  onresize(e) {
    //
  }

  render() {
    const {src, className, nativeWidth, nativeHeight} = this.props;
    return (
      <div className={cn(className, s.focalImage)}>
        <div className={s.imageWrapper}>
          <img src={src} className={_compare_ratios_ ? s.tall : s.wide}/>
        </div>
      </div>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

reactjs isomorphic-javascript

2
推荐指数
1
解决办法
1032
查看次数

Grails app:JS文件混淆

我想用war文件中的最小化版本(由Closure Compiler最小化 - https://developers.google.com/closure/compiler/docs/gettingstarted_app)替换js 文件.为了建立战争,我正在使用蚂蚁:

...
<target name="war" depends="buildnumber" description="--> Creates a WAR of a Grails application">
    <grails command="war" environment="${grails.env}"/>
</target>
...
Run Code Online (Sandbox Code Playgroud)

我补充说:

grails.project.resources = { stagingDir ->
    delete(file:"${stagingDir}/js/*.js")
}
Run Code Online (Sandbox Code Playgroud)

到<root>\grails-app\conf\BuildConfig.groovy但是没有删除war文件的js文件.

如何在ant构建文件中提供最小化的文件列表,以及如何将其添加到最终war文件中?

更新:

我在\ grails-app\conf\BuildConfig.groovy中添加了以下内容,将最小化的文件复制到war文件中.在第一步中,ant最小化js文件.在下一步中生成war文件,此步骤用最小化文件替换原始js文件.

grails.war.resources = { stagingDir, args ->
    def jsFiles = [
            'file1.js',
            'file2.js',
            'file3.js',
            ...
            'templates.common.js'
    ];
    for (file in jsFiles) {
        File f = new File("minimizedjs\\${file}");
        if(f.exists()) {
            copy(file: "minimizedjs\\${file}", tofile: "${stagingDir}\\js\\${file}")
        }
        else {
            println('.....!');
            break;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

ant grails war google-closure-compiler

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

if let Some 和 match 的区别

试图了解什么是错误的

fn set_inpt_port_values1(&mut self, input_port_values: HashMap<u8, u8>) {
    if let Some(mut io_handler) = self.io_handler {
       io_handler.set_input_ports_values(input_port_values);
    }
}
Run Code Online (Sandbox Code Playgroud)

得到

cannot move out of `self.io_handler.0` which is behind a mutable referencerustcE0507
i808x.rs(2333, 21): data moved here
i808x.rs(2333, 21): move occurs because `io_handler` has type `Box<dyn IoHandler>`, which does not implement the `Copy` trait
i808x.rs(2333, 39): consider borrowing here
Run Code Online (Sandbox Code Playgroud)

另一方面,类似的功能

fn set_inpt_port_values(&mut self, input_port_values: HashMap<u8, u8>) {
    match &mut self.io_handler {
        Some(io_handler) => {
            io_handler.set_input_ports_values(input_port_values);
        }
        _ => (),
    }
}
Run Code Online (Sandbox Code Playgroud)

工作/编译正常(可能 …

rust

0
推荐指数
1
解决办法
94
查看次数