跳到主要内容
未找到任何项目。
dropboxsign 徽标
为什么选择 Dropbox Sign?
展开或折叠手风琴

您可以做什么

在线签署文档
创建电子签名
选择或创建模板
填写和签署 PDF
完成线上合同
文档管理
探索功能
向右箭头图标

用例

销售与业务拓展
人力资源
初创公司
金融科技
房地产
按需服务
产品
展开或折叠手风琴
Dropbox 图标
Sign
实现轻松发送和签字
Dropbox 图标
Sign API
将电子签名集成到您的工作流程中
dropbox fax 图标
Fax
无需传真机便能发送传真
dropbox 集成图标
集成
无缝集成助力您轻松工作
资源
展开或折叠手风琴
博客
工作流程专业知识和产品新闻
客户案例
讲述取得实际成果的真实故事
帮助中心
关于我们产品的深入指南
资源库
报告、视频和信息表
开发人员
定价
展开或折叠手风琴
Dropbox Sign 定价
找到适合您的套餐
Dropbox Sign API 定价
讲述取得实际成果的真实故事
与销售人员联系
注册
联系销售人员
登录
展开或折叠手风琴
Dropbox Sign
Dropbox Forms
Dropbox Fax
免费试用版
博客
/
开发人员

React Rocks: Redesign Your Front-End for Composability

by 
Aron Solberg
November 17, 2014
7
分钟阅读时间
Redesign Your Front-End for Composability
工具提示图标

外观全新但功能同样出色的产品!HelloSign 现为 Dropbox Sign。

关闭图标

Back in May 2014, the Dropbox Sign website (like a lot of others) had a classic view layer consisting of templates, partials, vanilla CSS stylesheets, and a handful of supporting libraries like jQuery. This setup was simple to implement, universally understood, and at the time the original Dropbox Fax site was established in 2010 pretty much the standard way of doing things around the web. 

‍

However, as our platform grew in feature-set and complexity the frontend code began to accumulate signs of “technical debt.” A page that once contained only a handful of simple flows gradually evolved into an intimidating maze of jQuery event handlers and complex JavaScript logic. Each new commit felt like trouble was lurking in hidden places, and even changes that should have been simple became a chore. Not surprisingly the QA time required to deploy new front-end features likewise increased. 

‍

Meanwhile, JavaScript technologies were advancing rapidly and a number of new approaches were gaining momentum, all of which promised a better way of doing things. We decided a little research was warranted to better understand our options. 

‍

Our initial discovery effort involved us looking at a few popular technologies such as Backbone, Knockout, and Angular but for various reasons none of them seemed like a good fit. But then we noticed a relative newcomer on the front-end scene: a small library from Facebook called React. 

‍

At first glance React looked like a lightweight frontend library that focused specifically on the view layer and was generally unopinionated on surrounding technologies. It also appeared to be an excellent choice for writing drop-in replacements (i.e. refactoring code in pieces) for those pages that we weren’t ready to entirely re-write.

‍

Enter React

‍

React brought a number of innovative ideas to the table and it was remarkably easy to pick up. While some frameworks like Angular and Meteor emphasized “two-way data binding” React encouraged the developer to write code in which data flows in only one direction (from parent to child). 

‍

While this might seem like it could be inconvenient, it does have the remarkable advantage of being easy to debug and reason about. Finding where data changes occur usually is a simple matter of finding usages for “setState” which (in a vanilla React implementation) will always be set explicitly. Note: it’s also possible to implement implicit two-way data bindings in React using helpers).

‍

Another innovative feature is the JSX syntax which is how React blends markup and javascript together into a high-level abstraction. It’s a departure from classic unobtrusive JavaScript; but the creators argued that separation-of-technologies is actually not the same thing as separation-of-concerns. The syntax seemed a little strange at first but it was hard to argue with the practicality of the end-result: portable interactive components which contained within them everything needed to declaratively render on a page. 

‍

Speaking of rendering, React does it with a nifty trick. It maintains an in-memory virtual DOM and when updates to the real DOM are required, it calculates a diff and a kind of “shortest path” so that expensive update operations can be minimized. 

‍

The technology was impressive; but we felt even more strongly drawn to the development philosophy. The idea of breaking components up into their constituent parts and nesting them within each other opened up a whole world of possible design patterns. The virtual DOM and JSX syntax were cool, but this composability idea was what really got our interest piqued. After all, the  core design philosophy seemed aimed at solving many of the same problems we were facing in maintaining unwieldy separate technologies and javascript files - we were impressed. 

‍

We decided to design a first simple composable component to see how it would look in our dev stack.

‍

Composable Buttons

‍

Much has already been written about how to use React, so we won’t recreate a tutorial here. But just for context it’s important to know that data exists in one of two forms: props and state. 

‍

Props are passed from parent to child and don’t change directly as a result of user interaction. State on the other hand does change with user interaction and a common pattern is to allow the state of the parent component determine the props which ultimately get passed down to its children. It’s a declarative approach with both data types combined governing how the component will render at any given moment. 

‍

With the basic thought process in mind, let’s dive into a real example to see how we used React to create composable buttons to use in our new design. The first step was to create a base type to provide all the functionality that every button would share. This might remind you a bit of object-oriented programming and indeed the basic tenets are similar: encapsulation and inheritance. 

‍

‍

If we wanted we could extend this in other ways to include things like dimensions and corner style, but this is a great starting point. Now, whenever we need to place a button, we could use this BaseButton and specify all of its styling including text, background-color, hover-color, and font-color. 

‍

A better approach would be to create a higher-level abstraction which has the pre-defined settings for the specific types of buttons that we use in our style guide for example a “GreenButton” and a “BlueButton.” This should help enforce consistency and reduce repetition. 

‍

‍

‍

Now, a quick lookup in our internal style guide should be all that’s required to understand the visual forms possible and the limited props required to make each one work correctly. If a new variation is desired, the groundwork has already been laid to accommodate it. Best of all, we’re confident that using React for this functionality is faster and less-error prone than the way we had done things before.

‍

Composable Modals

‍

Our new design also makes liberal use of popup modals for important user actions. One reason we like the modal approach is it feels less disruptive for things like logging in and signing up a new account. In these moments we want our customers to easily see their origin in the background and be able to return to it by simply closing the modal. 

‍

For the basic styling we’re using Foundation’s Reveal, but for control and behavior we again turned to React. In this case we wanted to build a base modal component which defined all the shared functionality including open/close triggers and required DOM attach points. We also wanted the content to be interchangeable and ideally for them to work in a non-modal context as well. 

‍

Here is an example of a ModalTrigger component which will launch a modal when fired. It accepts the basic props to build the modal itself and also looks for a separate passed in component to render the content (TriggerContent). 

‍

‍

The TriggerContent component will vary but can include things such as the “CreateAccount” form and the “Credit card Payment” form. For reference here’s a slimmed down gist of our “CreateAccount” component which also doubles as a login form and could be used for the TriggerContent prop. 

‍

Now we can render BaseModal component and pass as a prop the CreateAccount component. This will give us the content in modal form.

‍

‍

And the result:

‍

‍

Alternatively, we can use the “isInline” property (which conditionally apply CSS rules) allowing the modal to appear within the normal flow of the page. All other functionality remains the same including form validation, submission, and the overall responsive design.

‍

‍

 Which renders like so:

‍

‍

A different kind of trigger

‍

You may have noticed that we have a “Trigger” prop which is optionally passed into our ModalTrigger. If not present we’ll use anchor text but in many cases it would look a lot nicer to use a button instead. So as a final example, here is how we might utilize the “BlueButton” component we built previously to act as the trigger. This really illustrates how React's composability makes it so powerful, versatile, and fun to work with. 

‍

‍

Looking ahead

‍

Overall our first experience using React was a positive one. We’re planning to use the knowledge we gained from this effort and apply it toward future redesign and development efforts (including our internal pages, stay tuned!). We’re also looking forward to continue working with React to support cleaning up old code while simultaneously adding new features to support our expanding user base. 

‍

Also on the horizon for us will likely be the inclusion of a model layer to better manage data flow from the backend to the frontend. Some have chosen to implement Backbone alongside React for just this purpose while others have gone a different route and used an accompanying Facebook library called Flux. 

‍

Regardless of which approach we take, the lines of abstraction in our front-end stack have been drawn and future improvements seem easily within reach.We hope you enjoyed this brief foray into how we used React to level-up our frontend code. 

‍

If you liked this article make sure to check out the next two parts where we'll talk about styling and our internal developer workflow. 

‍

If you’re a developer and this stuff speaks to you on a deeper level give us a shout, we’re hiring.If you want to hop into our API documentation, visit here.

保持更新

完成!请检查您的收件箱。

Thank you!
Thank you for subscribing!

Lorem ipsum

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.

Lorem ipsum
向右箭头图标
关闭图标

Up next:

手写签名的特写插图,代表现代数字签名解决方案。
开发人员
15
分钟阅读时间

将 Dropbox Sign 与 Ruby on Rails 集成:分步教程

手写签名的特写插图,代表现代数字签名解决方案。
开发人员
15
分钟阅读时间

Dropbox Sign vs. SignNow for developers

Video

使用 Dropbox Sign 在 Java 中设置嵌入式签字

产品
Dropbox SignDropbox Sign APIDropbox Fax集成
为什么选择 Dropbox Sign
电子签名签署文档签署和填写 PDF在线合同创建电子签名签名编辑器签署 Word 文档
支持
帮助中心与销售人员联系联系支持人员管理 Cookie开始使用:Dropbox Sign开始使用:Dropbox Sign API
资源
博客客户案例资源中心合法性指南信任中心
合作伙伴
战略合作伙伴合作伙伴查找工具
公司
招贤纳士条款隐私
Facebook 图标YouTube 图标

接受的付款方式

Mastercard 徽标Visa 徽标American Express 徽标Discover 徽标
CPA 合规标记HIPAA 合规标记Sky High Enterprise Ready 标记ISO 9001 认证标志

在美国、欧盟、英国和世界许多其他地区,Dropbox Sign 电子签名均具有法律约束力。
如需了解更多信息,请查看我们的条款和条件以及隐私政策