Giter Site home page Giter Site logo

ember-awesome-macros's People

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

ember-awesome-macros's Issues

reduce initial value is not recycled

The initial value you provide is mutated and reused for each computation. It needs to be a fresh copy. @Turbo87 suggested to turn it into a factory function you supply that gives a fresh value every calculation.

add date macros

We can use the same method as math, but should probably wait until #259 because of the bloat.

`array.sort` breaks on DS.PromiseArray

Fails on this line, complaining Uncaught TypeError: array.sort is not a function

Indeed, Ember.ArrayProxy doesn't seem to implement a sort method (which I guess makes sense, since it's not entirely clear what it should do)

The official Ember.computed.sort() does a slice() to copy the array before sorting

I haven't delved into the ember-awesome-macros code far enough to see where the parameter passed into ember-awesome-macros/array.sort() originates, but it seems like doing the same slice()-to-copy should fix this issue (and probably avoid others -- right now the original array is being mutated when the sort macro is accessed, which I certainly found unexpected)

htmlSafe not exported from string index

After receiving the deprecation warning about htmlSafe moving to string.htmlSafe I tried to do the following: import { htmlSafe} from 'ember-awesome-macros/string' but it is missing.

it looks like the string index does not export htmlSafe. I would assume it should (as well as a few others that appear to be missing).

If @kellyselden agrees that this is an issue, I can implement the fix for this.

Some of the macro names are out of date in the README

I was getting an import error for lt and looked at the addon folder and saw that lt was defined in lt-key.js. I noticed most of comparison macros are named similarly.

Uncaught Error: Could not find module `ember-awesome-macros/lt` imported from `frontend/pods/components/appointments-list/component`

It's a bit more cryptic if you import in this way: import { lt } from 'ember-awesome-macros';, because you get the error:

Uncaught TypeError: (0 , _emberAwesomeMacros.lt) is not a function

Pleeeeease add a changelog

otherwise it's really hard to figure out what the breaking changes are between each version... ๐Ÿ˜ญ

repo description typo

two things:

  • the Github repo description currently reads: A ollection(sic) of Ember computed macros
  • this library is awesome

Unless macro

Instead of using one of these:

conditional(not('value'), raw('some text'))
conditional('value', raw(''), raw('some text'))

Would be nice to have something easier

Undefined keys are ignored in logic macros

When a key is undefined, it is skipped when the macro is calculated. This has unexpected consequences when working with the logic macros (and, or, etc). For example, an and of a true property and an undefined property will resolve as true.

Reexport raw() and other helpers

It seems annoying that you have to import raw() and computed() from a different addon than ember-awesome-macros itself. IMHO we should reexport those macros if we depend on them as our own public API.

every(mapBy()) does not recalculate when mapped properties change

So I have a CP like this:

  areAllShorterThanFive_cp: Ember.computed('[email protected]', function () {
    return this
    	.get('data')
    	.mapBy('name')
    	.every(name => name.length < 5)
  }),  

I've assumed it can be rewritten with ember-awesome-macros like this:

  areAllShorterThanFive_every_mapBy:
    every(
      mapBy('data', 'name'),
      item => item.get('name').length < 5
    ),

But the latter does not recalculate. :(

Here's a demo: https://ember-twiddle.com/0dc43e01f156470d6c427f856963e0f4?openFiles=controllers.application.js%2C

I also tried this:

  areAllShorterThanFive_every: every('[email protected]',
    item => item.get('name').length < 5
  ),

but it produces a warning "You used the key "[email protected].[]" which is invalid." and still does not work.

We definitely need an everyBy macro, but why doesn't every(mapBy()) work? Is there a way to make it work? Either it's a bug or I'm missing something important about the addon. I wonder how many issues like this I already have in my apps.

`conditional` computes unnecessary property

I am not sure whether this is intended or avoidable behavior, but in a scenario where you have the following:

condition: false,

property: conditional('condition', 'trueProp', 'falseProp'),

falseProp: computed(function() {
  // we expect this to be called
  return 'good'
}),

trueProp: computed(function() {
  // but not this one
  // this property could incorrectly assume that `condition` is true
  // or it could be very slow
  // etc
})

Essentially, the second argument to condition could possibly not be executed until the first argument becomes true.

Thoughts?

Incomplete dependent keys

I just recognized some of the macros use incomplete dependent keys. I looked at the array.filterBy macro for example and realized that with this example:

model: Ember.A([
  Ember.Object.create({ val: 1 }),
  Ember.Object.create({ val: 2 })
]),
filterKey: 'val',
number2: filterBy('model', 'filterKey', 2)

the number2 property doesn't update when any of the model's objects' val property changes (as the [email protected] dependent key is missing from the CP).

I think in the case of macros like this that take only atomic arguments this should be fixable (might be much harder for macros like array.filter where you'd have to inspect the passed function to get the element property that the CP needs to depend on). Having an incomplete implementation like this might lead to hard to track down bugs.

remove promiseObject and promiseArray function syntax

test: promiseObject(function() {
  return this.store.findRecord('item');
})

should be

test: promiseObject(computed(function() {
  return this.store.findRecord('item');
}))

no other macros have function syntax, we should use what computed already gives us.

Figure out how to handle setting

Existing settable computed properties don't translate well to macros. Figure out how to handle. I'm thinking:

test: setable(and('test1', 'test2')) will overwrite the property

test: setable(and('test1', 'test2'), {
  set(key, value) {
    set(this, 'test1', value);
  }
})

to do something custom.

This is purely for backwards compatibility, and should not be used for new code as it is a bad practice.

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.