Forgotten 2 files sorry
This commit is contained in:
parent
b0ae0d2faa
commit
fc326e85d5
|
@ -0,0 +1,35 @@
|
||||||
|
# TypeScript none standard JSDOC Import syntax
|
||||||
|
```js
|
||||||
|
// 1.Normal Case
|
||||||
|
/**
|
||||||
|
* @param {import('./user').User} user
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// typescript
|
||||||
|
// 1. normal
|
||||||
|
/**
|
||||||
|
* @param p { import("./a").Pet }
|
||||||
|
*/
|
||||||
|
function walk(p) {
|
||||||
|
console.log(`Walking ${p.name}...`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2.Alias Type
|
||||||
|
/**
|
||||||
|
* @typedef { import("./a").Pet } Pet
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Pet}
|
||||||
|
*/
|
||||||
|
var myPet;
|
||||||
|
myPet.name;
|
||||||
|
|
||||||
|
// 3.Refer Inferred Type
|
||||||
|
/**
|
||||||
|
* @type {typeof import("./a").x }
|
||||||
|
*/
|
||||||
|
var x = require("./a").x;
|
||||||
|
```
|
|
@ -0,0 +1,61 @@
|
||||||
|
/**
|
||||||
|
* User session model
|
||||||
|
* @type {Object} Session Object.
|
||||||
|
* @property {string} _sessionId The session identifier
|
||||||
|
* @property {string} _websiteKey The website id for session
|
||||||
|
*/
|
||||||
|
export class UserSession {
|
||||||
|
/**
|
||||||
|
* Set session ID
|
||||||
|
* @param {string} id
|
||||||
|
*/
|
||||||
|
set sessionId(id) {
|
||||||
|
this._sessionId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the session ID
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
get sessionId() {
|
||||||
|
return this._sessionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set session ID
|
||||||
|
* @param {string} id
|
||||||
|
*/
|
||||||
|
set websiteKey(id) {
|
||||||
|
this._websiteKey = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the session ID
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
get websiteKey() {
|
||||||
|
return this._websiteKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize the session into a JSON object
|
||||||
|
* @return {Array<any>}
|
||||||
|
*/
|
||||||
|
serialize() {
|
||||||
|
const {sessionId, websiteKey} = this;
|
||||||
|
if (!sessionId || !websiteKey) {
|
||||||
|
throw Error();
|
||||||
|
}
|
||||||
|
return [sessionId, websiteKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deserialize session data from JSON object
|
||||||
|
* @param {Array<any>} payload
|
||||||
|
*/
|
||||||
|
deserialize([sessionId, websiteKey]) {
|
||||||
|
Object.assign(this, {sessionId, websiteKey});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default UserSession;
|
Loading…
Reference in New Issue