-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
979799b
commit 2deef3f
Showing
13 changed files
with
406 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import QueryParams from '../../query-params'; | ||
|
||
const QP_MAP = new WeakMap(); | ||
|
||
export function getQueryParamsFor(klass) { | ||
QP_MAP.set(klass, QP_MAP.get(klass) || new QueryParams()); | ||
|
||
return QP_MAP.get(klass); | ||
} | ||
|
||
export function addQueryParamFor(klass, key, definition) { | ||
QP_MAP.set( | ||
klass, | ||
getQueryParamsFor(klass).extend({ [key]: definition || {} }) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as queryParam } from './query-param'; | ||
export { default as withParachute } from './with-parachute'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { | ||
addQueryParamFor, | ||
getQueryParamsFor | ||
} from './-private/query-params-for'; | ||
|
||
function createDescriptor(desc, qpDefinition) { | ||
qpDefinition = qpDefinition || {}; | ||
|
||
const descriptor = { | ||
...desc, | ||
finisher(klass) { | ||
addQueryParamFor(klass, desc.key, qpDefinition); | ||
klass.reopen(getQueryParamsFor(klass).Mixin); | ||
|
||
return klass; | ||
} | ||
}; | ||
|
||
if (desc.kind === 'field') { | ||
if (typeof desc.initializer === 'function') { | ||
qpDefinition.defaultValue = desc.initializer(); | ||
} | ||
|
||
descriptor.initializer = function initializer() { | ||
return qpDefinition.defaultValue; | ||
}; | ||
} | ||
|
||
return descriptor; | ||
} | ||
|
||
export default function queryParam(qpDefinition) { | ||
// Handle `@queryParam` usage | ||
if (`${qpDefinition}` === '[object Descriptor]') { | ||
return createDescriptor(qpDefinition); | ||
} | ||
|
||
// Handle `@queryParam()` usage | ||
return desc => createDescriptor(desc, qpDefinition); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import QueryParams from '../query-params'; | ||
|
||
export default function withParachute(desc) { | ||
return { | ||
...desc, | ||
finisher(klass) { | ||
klass.reopen(new QueryParams().Mixin); | ||
|
||
return klass; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.