-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Angular versions support #2467
Changes from 4 commits
63be049
00106d3
3778ed9
e4ccd6d
6e6d36d
a55741d
fef3b98
154e510
baaa14b
fc980e7
eb252c7
68c119e
0a8c581
9cc09db
dd0d185
08b0bda
a1470f6
24873e7
6ed2fd8
1ecd649
cc32f92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* eslint-disable no-param-reassign */ | ||
/* globals window */ | ||
|
||
import { VERSION } from '@angular/core'; | ||
|
||
function getMeta(component, [name1, name2], defaultValue) { | ||
if (!name2) { | ||
name2 = name1; | ||
name1 = `__${name1}__`; | ||
} | ||
|
||
if (VERSION.major === '5') { | ||
if (component[name1]) { | ||
return component[name1]; | ||
} | ||
|
||
if (component[name2]) { | ||
return component[name2]; | ||
} | ||
} | ||
|
||
if (VERSION.major === '4') { | ||
return window.Reflect.getMetadata(name2, component) || defaultValue; | ||
} | ||
|
||
return defaultValue; | ||
} | ||
|
||
function setMeta(component, [name1, name2], value) { | ||
if (!name2) { | ||
name2 = name1; | ||
name1 = `__${name1}__`; | ||
} | ||
|
||
if (VERSION.major === '5') { | ||
component[name1] = value; | ||
} | ||
|
||
if (VERSION.major === '4') { | ||
window.Reflect.defineMetadata(name2, value, component); | ||
} | ||
} | ||
|
||
export function getAnnotations(component) { | ||
return getMeta(component, ['annotations'], []); | ||
} | ||
|
||
export function getPropMetadata(component) { | ||
return getMeta(component, ['__prop__metadata__', 'propMetadata'], {}); | ||
} | ||
|
||
export function getParameters(component) { | ||
return getMeta(component, ['parameters'], []); | ||
} | ||
|
||
export function setAnnotations(component, value) { | ||
setMeta(component, ['annotations'], value); | ||
} | ||
|
||
export function setParameters(component, value) { | ||
setMeta(component, ['parameters'], value); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { VERSION } from '@angular/core'; | ||
|
||
function getMeta(component, [name1, name2]: any, defaultValue) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where can I put this util ? It's duplicated in two projects: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, @ndelangen, where would be the best place to put this util? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was under the impression that there was an ongoing effort to remove duplicate parts of the code to a core package. Dunno if that's still a thing for 3.3 tho. We might just leave this as is for the time being and wait for that core module to be ready (?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I agree There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was kinda decided to leave the refactor until after the initial release of 3.3, and release it as a patch. @shilman started the refactor branch, @Hypnosphi wanted to hold it off, if I remember correctly.
Please give me a bit more context so I can answer your question |
||
if (!name2) { | ||
name2 = name1; | ||
name1 = `__${name1}__`; | ||
} | ||
|
||
if (VERSION.major === '5') { | ||
if (component[name1]) { | ||
return component[name1]; | ||
} | ||
|
||
if (component[name2]) { | ||
return component[name2]; | ||
} | ||
} | ||
|
||
if (VERSION.major === '4') { | ||
return window['Reflect'].getMetadata(name2, component) || defaultValue; | ||
} | ||
|
||
return defaultValue; | ||
} | ||
|
||
function setMeta(component, [name1, name2]: any, value) { | ||
if (!name2) { | ||
name2 = name1; | ||
name1 = `__${name1}__`; | ||
} | ||
|
||
if (VERSION.major === '5') { | ||
component[name1] = value; | ||
} | ||
|
||
if (VERSION.major === '4') { | ||
window['Reflect'].defineMetadata(name2, value, component); | ||
} | ||
} | ||
|
||
export function getAnnotations(component) { | ||
return getMeta(component, ['annotations'], []); | ||
} | ||
|
||
export function getPropMetadata(component) { | ||
return getMeta(component, ['__prop__metadata__', 'propMetadata'], {}); | ||
} | ||
|
||
export function getParameters(component) { | ||
return getMeta(component, ['parameters'], []); | ||
} | ||
|
||
export function setAnnotations(component, value) { | ||
setMeta(component, ['annotations'], value); | ||
} | ||
|
||
export function setParameters(component, value) { | ||
setMeta(component, ['parameters'], value); | ||
} | ||
|
||
export function setPropMetadata(component, value) { | ||
setMeta(component, ['__prop__metadata__', 'propMetadata'], value); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,23 +14,23 @@ | |
}, | ||
"private": true, | ||
"dependencies": { | ||
"@angular/animations": "^5.0.0-beta.7", | ||
"@angular/common": "^5.0.0-beta.7", | ||
"@angular/compiler": "^5.0.0-beta.7", | ||
"@angular/core": "^5.0.0-beta.7", | ||
"@angular/forms": "^5.0.0-beta.7", | ||
"@angular/http": "^5.0.0-beta.7", | ||
"@angular/platform-browser": "^5.0.0-beta.7", | ||
"@angular/platform-browser-dynamic": "^5.0.0-beta.7", | ||
"@angular/router": "^5.0.0-beta.7", | ||
"@angular/animations": "4.3.5", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wanted to check if it works with v4 (#269 (comment)) |
||
"@angular/common": "4.3.5", | ||
"@angular/compiler": "4.3.5", | ||
"@angular/core": "4.3.5", | ||
"@angular/forms": "4.3.5", | ||
"@angular/http": "4.3.5", | ||
"@angular/platform-browser": "4.3.5", | ||
"@angular/platform-browser-dynamic": "4.3.5", | ||
"@angular/router": "4.3.5", | ||
"core-js": "^2.4.1", | ||
"rxjs": "^5.4.2", | ||
"zone.js": "^0.8.14" | ||
}, | ||
"devDependencies": { | ||
"@angular/cli": "1.3.0", | ||
"@angular/compiler-cli": "^5.0.0-beta.7", | ||
"@angular/language-service": "^5.0.0-beta.7", | ||
"@angular/compiler-cli": "4.3.5", | ||
"@angular/language-service": "4.3.5", | ||
"@storybook/addon-actions": "^3.3.0-alpha.4", | ||
"@storybook/addon-links": "^3.3.0-alpha.4", | ||
"@storybook/addon-notes": "^3.3.0-alpha.4", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have
lodash.debounce
in the project. Why not using it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have it available than let's use it. I was under the impression that we didn't :)