riot-parents

1.0.2 • Public • Published

Riot Parents

Build Status Coverage Status NPM Downloads NPM Downloads

This is a simple Riot.js mixin which helps with the issue of

this.parent.parent.someproperty

and replaces it with

this.parents(2).someproperty
with parents with parent
this.parents(0) this.parent
this.parents(1) this.parent.parent
this.parents(2) this.parent.parent.parent
this.parents(3) this.parent.parent.parent.parent

I realise that accessing deep ancestors like this makes your components perhaps more coupled that they should be. But sometimes it's nice to be able to drop elements into yielding components and still be able to easily communitcate with them.

Installing

npm install riot-parents

Usage

To add it to all tags

var parents = require('riot-parents')
riot.mixin(parents)

To add it to specific tags, load it the same way, but assign it a name

var parents = require('riot-parents')
riot.mixin("parents",parents)

Then you can use it within specific tags to access parent tags. eg.

<mylogin>
  <modal>
    <loginform>
      <formrow label="Username">
        <input oninput="{parents(2).handleInput}" name="username" type="text" />
      </div>
      <formrow label="Password">
        <label>Password</label>
        <input oninput="{parents(2).handleInput}" name="password" type="password" />
     </formrow>
    </loginform>
  </modal>
  
  <script>
    this.mixin('parents') // <-- don't need this if you've installed it globally
    this.handleInput = function(e){
      this[e.target.name] = e.target.value
    }
  </script> 
</mylogin>
 

License

(The MIT License)

Copyright (c) 2015 Cris Ward

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Dependencies (0)

    Dev Dependencies (24)

    Package Sidebar

    Install

    npm i riot-parents

    Weekly Downloads

    0

    Version

    1.0.2

    License

    MIT

    Last publish

    Collaborators

    • crisward