Coder Social home page Coder Social logo

softlayer / sl-ember-behavior Goto Github PK

View Code? Open in Web Editor NEW
17.0 17.0 6.0 4.55 MB

An Ember CLI Addon that provides the ability to define and enforce behaviors, combining the concepts of whether a user has permission to perform an action and whether that action can currently be performed.

Home Page: http://softlayer.github.io/sl-ember-behavior/

License: MIT License

JavaScript 84.53% HTML 15.42% CSS 0.05%

sl-ember-behavior's People

Contributors

ember-tomster avatar jonathandavidson avatar joshforisha avatar juwara0 avatar notmessenger avatar yogeswar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sl-ember-behavior's Issues

Add more testing around 'mixins/component' showContent computed property

Specifically, we have a gap in testing around the showContent property. Tests should be added to:

  1. Test that the Ember.assert is thrown when the possible property is not a boolean
  2. Test that the computed property returns the value isViewable() returns

The computing of this property can be triggered in these tests by calling .get( 'showContent' ) on the test subject.

Allow provider to return simple boolean values instead of functions

I found myself in a situation where I would like to have custom behavior for individual providers.
However instead of defining a function I would like to return simple booleans. So the behavior data for an individual provider would look like this:

{
  project: true,
  project.edit: false
}

Currently I accomplish this by overriding the isAble function via an initializer. It would be nice to have this option out-of-the-box.

Changes to the isAble function to accomplish this idea:

      var behaviors = this.getWithDefault( 'behaviors', null ),
          isAble    = false,
          behaviorGroup,
          providerIsObject,
          providerBehavior;

[...]

      if ( behaviors && behaviors[behaviorGroup] && behaviors[behaviorGroup][behavior] ) {
        providerBehavior = ( providerIsObject  ) ? provider.behaviors[behavior] : true;

        isAble = ('function' === typeof providerBehavior) ? providerBehavior() : providerBehavior;
      }

Refactor DocBlocks

  • use @returns over @return
  • use @return {undefined} when function does not return anything
  • param types should be their most generic form - Array vs Ember.Array, Object vs Ember.Object - except for cases in which a more specific Ember.* type is warranted.
  • types should be capitalized - Number, Boolean, Object, Function - all except for "undefined" which should be all lowercase.

Add assertion for Symbol in appropriate tests

tests/unit/services/sl-behavior-test.js

  • "getBehaviorGroup() requires an Object to be provided"
  • "getBehaviorGroup() "provider.behaviorGroup" must be a String or Function"
  • "setBehaviors() requires an Object to be provided"
  • "isAble() requires two arguments to be provided"
  • "isAble() requires first argument to be a String"
  • "isAble() requires second argument to be a String or Object"

Reverse the change introduced in Issue #36

Through usage of a service in the sl-ember-components repo we have discovered that a component needing a service from the same library must have it exported in the fashion we were hoping to avoid due to needing it in the correct namespace and of the correct/known name. This means that instead of approaching this issue the way we did we will instead have to export a uniquely-named service to avoid any potential collisions with any other services "in the wild" used in a consuming application.

Test should assert null

test( 'getBehaviorGroup() requires an Object to be provided', function( assert ) {

test( 'getBehaviorGroup() "provider.behaviorGroup" must be a String or Function', function( assert ) {

test( 'setBehaviors() requires an Object to be provided', function( assert ) {

test( 'isAble() requires first argument to be a String', function( assert ) {

test( 'isAble() requires second argument to be a String or Object', function( assert ) {

Simplify parameters on sl-able and sl-unable

There is some unnecessary complexity in the provider parameter when an object is supplied. In order to simplify this feature without sacrificing any functionality, the sl-able and sl-unable components will be revised as follows:

  • The behavior parameter will be renamed resource and will otherwise remain unchanged
  • The provider parameter will be renamed activity and will no longer accept an object, only a string corresponding to the Behavior Group key name used in the Behaviors structure
  • An additional possible parameter will be added which accepts a boolean, computed property that evaluates to a boolean, or a function returning a boolean. This will take the place of the behaviors object passed in through the provider parameter since only one behavior (activity) is being evaluated in a component instance.
  • The possible parameter will be observed to make the component responsive to changes in the value supplied.

Does isUnable()'s logic need to be refined?

If the defined behaviors used by the Behavior Service were purely a true/false condition, where each behavior concept in the app is in the list then isUnable() being a pure inverse of a call to isAble() would be fine.

However, since all behaviors do not need to be pre-defined, the absence of one results in a false during a call to isAble().

Given this, is it reasonable that a call to isUnable() would return a true in such a condition, or should it return false in situations where the behavior has not been defined and then be an inverse to the remaining isAble() logic?

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.