Page MenuHomePhabricator

common.js to reproduce T364518

Authored By
Sportzpikachu
May 9 2024, 6:45 PM
Size
1 KB
Referenced Files
None
Subscribers
None

common.js to reproduce T364518

mw.loader.using( [ 'vue', 'pinia' ], ( require ) => {
const vue = require( 'vue' );
// vue-demi fix, uncomment to enable
/*
vue.set = function ( target, key, val ) {
if ( Array.isArray( target ) ) {
target.length = Math.max( target.length, key );
target.splice( key, 1, val );
return val;
}
target[ key ] = val;
return val;
};
vue.del = function ( target, key ) {
if ( Array.isArray( target ) ) {
target.splice( key, 1 );
return;
}
delete target[ key ];
};
*/
const pinia = require( 'pinia' );
const useCounter = pinia.defineStore( 'counter', () => {
const count = vue.ref( 0 );
const increment = () => count.value++;
return { count, increment };
} );
const app = vue.createMwApp( {
setup() {
const counter = useCounter();
return () => vue.h( 'button', { onClick: () => counter.increment() }, [
'Count: ',
counter.count,
] );
},
} );
app.use( pinia.createPinia() );
app.mount( '#app' );
const hot = {
data: {},
};
const hmr = pinia.acceptHMRUpdate( useCounter, hot );
$( '<button>Trigger HMR</button>' ).one( 'click', () => {
hmr( {
useCounter: pinia.defineStore( 'counter', () => {
const count = vue.ref( 0 );
const increment = () => ( count.value += 2 );
return { count, increment };
} ),
} );
} ).insertAfter( '#app' );
} );

File Metadata

Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
17039008
Default Alt Text
common.js to reproduce T364518 (1 KB)

Event Timeline