mirror of
https://github.com/taigrr/wails.git
synced 2026-04-15 19:30:49 -07:00
Compare commits
4 Commits
v1.7.2-pre
...
sync-store
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b110e4ae5 | ||
|
|
861f5f2a1c | ||
|
|
89ed00d6ed | ||
|
|
1e1834158b |
@@ -7,18 +7,25 @@
|
|||||||
"start": "sirv public"
|
"start": "sirv public"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.11.6",
|
||||||
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
||||||
|
"@babel/plugin-transform-runtime": "^7.11.5",
|
||||||
|
"@babel/preset-env": "^7.11.5",
|
||||||
"@rollup/plugin-commonjs": "^14.0.0",
|
"@rollup/plugin-commonjs": "^14.0.0",
|
||||||
"@rollup/plugin-image": "^2.0.5",
|
"@rollup/plugin-image": "^2.0.5",
|
||||||
"@rollup/plugin-node-resolve": "^8.0.0",
|
"@rollup/plugin-node-resolve": "^8.0.0",
|
||||||
|
"core-js": "^3.6.5",
|
||||||
"rollup": "^2.3.4",
|
"rollup": "^2.3.4",
|
||||||
|
"rollup-plugin-babel": "^4.4.0",
|
||||||
"rollup-plugin-livereload": "^2.0.0",
|
"rollup-plugin-livereload": "^2.0.0",
|
||||||
|
"rollup-plugin-polyfill": "^3.0.0",
|
||||||
"rollup-plugin-svelte": "^6.0.0",
|
"rollup-plugin-svelte": "^6.0.0",
|
||||||
"rollup-plugin-terser": "^7.0.0",
|
"rollup-plugin-terser": "^7.0.0",
|
||||||
"svelte": "^3.0.0"
|
"svelte": "^3.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"sirv-cli": "^1.0.0",
|
"sirv-cli": "^1.0.0",
|
||||||
"@wailsapp/runtime": "^1.0.10",
|
"@wailsapp/runtime": "^1.0.10",
|
||||||
"svelte-simple-modal": "^0.6.0"
|
"svelte-simple-modal": "^0.6.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import commonjs from '@rollup/plugin-commonjs';
|
|||||||
import livereload from 'rollup-plugin-livereload';
|
import livereload from 'rollup-plugin-livereload';
|
||||||
import { terser } from 'rollup-plugin-terser';
|
import { terser } from 'rollup-plugin-terser';
|
||||||
import image from '@rollup/plugin-image';
|
import image from '@rollup/plugin-image';
|
||||||
|
import babel from 'rollup-plugin-babel';
|
||||||
|
import polyfill from 'rollup-plugin-polyfill';
|
||||||
|
|
||||||
const production = !process.env.ROLLUP_WATCH;
|
const production = !process.env.ROLLUP_WATCH;
|
||||||
|
|
||||||
@@ -67,6 +69,37 @@ export default {
|
|||||||
// browser on changes when not in production
|
// browser on changes when not in production
|
||||||
!production && livereload('public'),
|
!production && livereload('public'),
|
||||||
|
|
||||||
|
// Credit: https://blog.az.sg/posts/svelte-and-ie11/
|
||||||
|
babel({
|
||||||
|
extensions: [ '.js', '.jsx', '.es6', '.es', '.mjs', '.svelte', '.html' ],
|
||||||
|
runtimeHelpers: true,
|
||||||
|
exclude: [ 'node_modules/@babel/**', 'node_modules/core-js/**' ],
|
||||||
|
presets: [
|
||||||
|
[
|
||||||
|
'@babel/preset-env',
|
||||||
|
{
|
||||||
|
targets: '> 0.25%, not dead, IE 11',
|
||||||
|
modules: false,
|
||||||
|
spec: true,
|
||||||
|
useBuiltIns: 'usage',
|
||||||
|
forceAllTransforms: true,
|
||||||
|
corejs: 3,
|
||||||
|
},
|
||||||
|
|
||||||
|
]
|
||||||
|
],
|
||||||
|
plugins: [
|
||||||
|
'@babel/plugin-syntax-dynamic-import',
|
||||||
|
[
|
||||||
|
'@babel/plugin-transform-runtime',
|
||||||
|
{
|
||||||
|
useESModules: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}),
|
||||||
|
polyfill(['@webcomponents/webcomponentsjs']),
|
||||||
|
|
||||||
// If we're building for production (npm run build
|
// If we're building for production (npm run build
|
||||||
// instead of npm run dev), minify
|
// instead of npm run dev), minify
|
||||||
production && terser()
|
production && terser()
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ body {
|
|||||||
display: block;
|
display: block;
|
||||||
width:100%;
|
width:100%;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin-top: 3rem;
|
margin-top: 1rem;
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.result {
|
.result {
|
||||||
margin-top: 3rem;
|
margin-top: 1rem;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ function start() {
|
|||||||
mystore.set(newValue);
|
mystore.set(newValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
mystore.subscribe( (state) => {
|
mystore.subscribe( function(state) {
|
||||||
document.getElementById('counter').innerText = state;
|
document.getElementById('counter').innerText = state;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
// Version - Wails version
|
// Version - Wails version
|
||||||
const Version = "v1.7.2-pre8"
|
const Version = "v1.7.2-pre9"
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ type Store struct {
|
|||||||
data reflect.Value
|
data reflect.Value
|
||||||
dataType reflect.Type
|
dataType reflect.Type
|
||||||
eventPrefix string
|
eventPrefix string
|
||||||
callbacks []func(interface{})
|
callbacks []reflect.Value
|
||||||
runtime *Runtime
|
runtime *Runtime
|
||||||
notifySynchronously bool
|
notifySynchronously bool
|
||||||
|
|
||||||
@@ -143,10 +143,13 @@ func (s *Store) notify() {
|
|||||||
// Execute callbacks
|
// Execute callbacks
|
||||||
for _, callback := range s.callbacks {
|
for _, callback := range s.callbacks {
|
||||||
|
|
||||||
|
// Build args
|
||||||
|
args := []reflect.Value{s.data}
|
||||||
|
|
||||||
if s.notifySynchronously {
|
if s.notifySynchronously {
|
||||||
callback(s.data)
|
callback.Call(args)
|
||||||
} else {
|
} else {
|
||||||
go callback(s.data)
|
go callback.Call(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -184,11 +187,50 @@ func (s *Store) Set(data interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// callbackCheck ensures the given function to Subscribe() is
|
||||||
|
// of the correct signature. Absolutely cannot wait for
|
||||||
|
// generics to land rather than writing this nonsense.
|
||||||
|
func (s *Store) callbackCheck(callback interface{}) error {
|
||||||
|
|
||||||
|
// Get type
|
||||||
|
callbackType := reflect.TypeOf(callback)
|
||||||
|
|
||||||
|
// Check callback is a function
|
||||||
|
if callbackType.Kind() != reflect.Func {
|
||||||
|
return fmt.Errorf("invalid value given to store.Subscribe(). Expected 'func(%s)'", s.dataType.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check input param
|
||||||
|
if callbackType.NumIn() != 1 {
|
||||||
|
return fmt.Errorf("invalid number of parameters given in callback function. Expected 1")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check input data type
|
||||||
|
if callbackType.In(0) != s.dataType {
|
||||||
|
return fmt.Errorf("invalid type for input parameter given in callback function. Expected %s, got %s", s.dataType.String(), callbackType.In(0))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check output param
|
||||||
|
if callbackType.NumOut() != 0 {
|
||||||
|
return fmt.Errorf("invalid number of return parameters given in callback function. Expected 0")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Subscribe will subscribe to updates to the store by
|
// Subscribe will subscribe to updates to the store by
|
||||||
// providing a callback. Any updates to the store are sent
|
// providing a callback. Any updates to the store are sent
|
||||||
// to the callback
|
// to the callback
|
||||||
func (s *Store) Subscribe(callback func(interface{})) {
|
func (s *Store) Subscribe(callback interface{}) {
|
||||||
s.callbacks = append(s.callbacks, callback)
|
|
||||||
|
err := s.callbackCheck(callback)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
callbackFunc := reflect.ValueOf(callback)
|
||||||
|
|
||||||
|
s.callbacks = append(s.callbacks, callbackFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// updaterCheck ensures the given function to Update() is
|
// updaterCheck ensures the given function to Update() is
|
||||||
|
|||||||
Reference in New Issue
Block a user