jeudi 23 février 2017

Where is a great place to introduce some constants into a project?

I would love to remove all the magic numbers inside my project, so I think import a constant to where they need to be is a great idea.

See my constant declaration below,

export default { validation: validation };

const validation = {
  password: 6,
  email: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
};

However when I try to import the constant into a component I get a import error which state the model could not be found.

Inside my component,

import Ember from 'ember';
import { validation } from '../../../../config/constants';

export default Ember.Component.extend({
  classNames: ['login-panel'],
  // ...
}

My question is where is a good place to store this kind of constants and how to import into it to the right place?




Aucun commentaire:

Enregistrer un commentaire