Giter Club home page Giter Club logo

Comments (4)

litson avatar litson commented on September 18, 2024

很高兴,其实我一直也会这么写,并且会为actionList里的每一个属性(action)重新指定上下文及event;
类似于:

actionList[actionName] && actionList[actionName].call(this,event);

好处是:
我们会有一些场景需要操作触发该action的元素;
坏处是:
trigger的时候,[context]就会出错,而且代码阅读起来会比较混乱;

请问有没有更好的方式解决这个问题?比如trigger的时候自动绑定正确的上下文?

from action.

cssmagic avatar cssmagic commented on September 18, 2024

@litson 谢谢留言。

trigger的时候,[context]就会出错,而且代码阅读起来会比较混乱;
请问有没有更好的方式解决这个问题?比如trigger的时候自动绑定正确的上下文?

Action 目前的设计可以参考这里(#19),最后一节讨论了 .trigger() 方法的使用问题。

from action.

anhulife avatar anhulife commented on September 18, 2024

个人觉得Backbone里面的event map也比较方便

events: {
  'click [data-action="my-action"]': 'doMyAction'
}

而且上下文是自动绑定

from action.

cssmagic avatar cssmagic commented on September 18, 2024

@anhulife 谢谢评论。

Backbone 的这种机制自然是极好的,但不是每个项目都会使用或适合使用 Backbone。Action 专注做这一件事,而且它要解决的问题十分通用,使得它适用于大多数项目。而且 Action 的体积十分小巧,minify + gzip 后只有 500 多字节,对任何项目来说几乎都是零负担。

关于 “上下文自动绑定”,Action 也是这样设计的。参见 #19

from action.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.