question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ES6/7 Decorator alternative

See original GitHub issue

I see in the example (https://github.com/tiberiuc/redux-react-firebase/blob/master/example/App.js)

@firebase()

and then later:

@firebase( [
  '/todos', // if list is too large you can use ['/todos']
])

I’m not sure why this happens twice, and what the decorator does exactly, and what the alternative would be with ES5.

Also, the comment // if list too large you can use ['/todos'] I don’t understand what this means, can you elaborate? (there is no difference in '/todos')

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
prescottpruecommented, Sep 19, 2016

@TrySpace the simple example of redux-firebasev3 shows implementing without decorators where the decorators example (interface is the same as this library)

Simple comparison:

With Decorators

@firebase(['/todos'])
@connect(
  ({firebase}) => ({
    todos: dataToJS(firebase, '/todos'),
    profile: pathToJS(firebase, 'profile')
  })
)

Without Decorators

const fbWrappedComponent = firebase(['/todos'])(App)

export default connect(
  ({firebase}) => ({
    todos: dataToJS(firebase, 'todos'),
    profile: pathToJS(firebase, 'profile')
  })
)(fbWrappedComponent)

I bet that @tiberiuc will add a similar example showing this in the future (he is just now back around).

1reaction
tiberiuccommented, Jun 12, 2016

first version

@firebase( [
  '/todos', 
])

it is the equivalent for firebase.ref.child('/todos').on('value', ..... ) that mean it will listen for value and each time a todo will change it will fetch the entire /todos tree as a single value. The problem is when you have a lot of todos, firebase have a limit of 10mb / node

while

@firebase( [
  ['/todos'], 
])

it is the equivalent for

firebase.ref.child('/todos').on('child_added', ..... )
firebase.ref.child('/todos').on('child_removed', ..... )
firebase.ref.child('/todos').on('child_changed', ..... )
firebase.ref.child('/todos').on('child_moved', ..... )

and it will fetch each todo item one by one and also listen for removed, changed, … events and is setting them into redux store one by one

the result of each version it is the same, the difference it is how it is fetching the results from firebase and of course when you have huge data ( more then 10mb ) then first version will just not work

let me know if you have any other questions

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exploring EcmaScript Decorators
Yehuda's decorators proposal seeks to enable annotating and modifying JavaScript classes, properties and object literals at design time while keeping a syntax ...
Read more >
ES-67 Oxford Brown ARBORCOAT Semi-Solid Exterior Color
ES-67 Oxford Brown ARBORCOAT Semi-Solid Exterior Color. Price: $73.18 (Price Includes NYS PaintCare Fee). Use Code SAVE20 In Shopping Cart To Save 20%...
Read more >
Alternatives to decorator pattern on data object arrays
Writing angular services, i found a pattern that i consider very convenient. I think it fits into the description of the decorator pattern....
Read more >
DEFY Extreme Acrylic Custom Solid Color Wood Stain
Use of alternative products or methods prior to sealing may produce unsatisfactory final results. DEFY Extreme Solid Wood Stain is sold in one...
Read more >
Decorate your code with TypeScript decorators | by Mohan Ram
Decorators are a proposed standard for ECMAScript 2016 by Yehuda Katz. We can pass user arguments to the decorator via decorator factories. ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found