MCPcopy
hub / github.com/sveltejs/svelte / #init

Method #init

packages/svelte/src/reactivity/date.js:62–121  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

60 }
61
62 #init() {
63 inited = true;
64
65 var proto = SvelteDate.prototype;
66 var date_proto = Date.prototype;
67
68 var methods = /** @type {Array<keyof Date & string>} */ (
69 Object.getOwnPropertyNames(date_proto)
70 );
71
72 for (const method of methods) {
73 if (method.startsWith('get') || method.startsWith('to') || method === 'valueOf') {
74 // @ts-ignore
75 proto[method] = function (...args) {
76 // don't memoize if there are arguments
77 // @ts-ignore
78 if (args.length > 0) {
79 get(this.#time);
80 // @ts-ignore
81 return date_proto[method].apply(this, args);
82 }
83
84 var d = this.#deriveds.get(method);
85
86 if (d === undefined) {
87 // lazily create the derived, but as though it were being
88 // created at the same time as the class instance
89 const reaction = active_reaction;
90 set_active_reaction(this.#reaction);
91
92 d = derived(() => {
93 get(this.#time);
94 // @ts-ignore
95 return date_proto[method].apply(this, args);
96 });
97
98 if (DEV) {
99 tag(d, `SvelteDate.${method}()`);
100 }
101
102 this.#deriveds.set(method, d);
103
104 set_active_reaction(reaction);
105 }
106
107 return get(d);
108 };
109 }
110
111 if (method.startsWith('set')) {
112 // @ts-ignore
113 proto[method] = function (...args) {
114 // @ts-ignore
115 var result = date_proto[method].apply(this, args);
116 set(this.#time, date_proto.getTime.call(this));
117 return result;
118 };
119 }

Callers 1

constructorMethod · 0.95

Calls 8

getFunction · 0.90
set_active_reactionFunction · 0.90
derivedFunction · 0.90
tagFunction · 0.90
setFunction · 0.90
setMethod · 0.65
applyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected