Code Monkey home page Code Monkey logo

ember-one-way-controls's Introduction

ember-one-way-controls Download count all time CircleCI npm version Ember Observer Score

Credit: @rwjblue's twiddle

Demo: http://ember-twiddle.com/2d7246875098d0dbb4a4

This addon provides a simple and consistent API to add form controls to your app. Each form control will not update the passed in value(s) directly. Instead it will send the update action with the updated value.

{{one-way-input value update=(action (mut value))}}

{{one-way-textarea value update=(action (mut value))}}

{{one-way-checkbox checked update=(action (mut checked))}}

{{one-way-radio selected option=option update=(action (mut selected))}}

{{one-way-select selected options=options update=(action (mut selected))}}

If you do not know the type of input before hand you could do the following:

{{component (concat "one-way-" type) value update=(action (mut value))}}

Each of the controls are documented in more detail in their own readme's:

Why?

With Glimmer landing in 1.13.x, native <input> elements can now be used in your apps, without the two way binding semantics of the {{input}} helper. Shifting to one way bindings ("data down, actions up") makes your app easier to reason about and debug, and is generally the idiomatic way of building Ember apps going forward.

Unfortunately, there is a small gotcha with using a native input like so:

<input
  value={{currentValue}}
  oninput={{action (mut currentValue) value="target.value"}}
>

In the following demo, move your cursor to a character in the middle of the value, and attempt to input new text. You will notice that your cursor immediately jumps to the end of the string, which is entirely unintuitive and annoying.

This addon fixes the cursor jumping issue by using readDOMAttr, which provides a way to read an element's attribute and update the last value Ember knows about at the same time. This makes setting an attribute idempotent.

Note: The cursor jumping issue has been fixed in Ember since 2.3.1.

Compatibility

This addon will work on Ember versions 1.13.x and up.

Installing the addon

ember install ember-one-way-controls

Contributing

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://www.ember-cli.com/.

Legal

DockYard, Inc © 2016

@dockyard

Licensed under the MIT license

ember-one-way-controls's People

Contributors

xiphiasuvella avatar homu avatar poteto avatar panthony avatar makepanic avatar ivanvanderbyl avatar jeffhertzler avatar courajs avatar bardzusny avatar musaffa avatar duggiefresh avatar hbrysiewicz avatar krivaten avatar raytiley avatar robbiespeed avatar rwjblue avatar rsocci avatar ewhite613 avatar tchak avatar

Watchers

 avatar James Cloos avatar

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.