-
-
Notifications
You must be signed in to change notification settings - Fork 927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bring back m.prop? #2095
Comments
But Mithril streams are just an upgrade to props — they're fully backward compatible unless I'm mistaken. Maybe a blog post of the "you may not need (any of the stream methods)" variety would be the thing? |
Streams are great, but it's still 100 lines vs a few. I'm probably being overly concerned about kb size :) |
👍
I'm not really sure that there's a particularly large group of actual target audience for this kind of thing... |
@gilbert You might be interested in this. It's basically an
Edit: Here's what I would actually add to core (one of two variants, each with their min+gzip added size):// `m.prop`-like, adds 19 bytes min+gzip
m.prop = function (store, onchange) {
return function (value) {
if (!arguments.length) return store
var old = store, func = onchange
store = value
if (typeof func === "function") {
onchange = null
func(store, old)
onchange = func
}
return value
}
}
// Separate getter/setter-like, adds 18 bytes min+gzip
m.prop = function (store, onchange) {
return {
get: function () { return store },
set: function (value) {
var old = store, func = onchange
store = value
if (typeof func === "function") {
onchange = null
func(store, old)
onchange = func
}
return value
}
}
} |
On one hand I'm not that concerned about the few kb extra, but on the other hand so far I've only used streams in an |
I'd be for 0.2x m.prop without the promise stuff, but I don't think So 👍 to m.prop, but if we want reactivity I think mithril should just make stream part of the main release and accept the extra 1.5kb because that 1.5kb is so so so useful. If we include @isiahmeadows I like having separate get/set methods, providing they are bound. If we made that change to |
I like these suggestions. Keep |
So removing the
function prop(store) {
return function (value) {
if (arguments.length) store = value
return store
}
}
function prop(store) {
return {
get: function () {
return store
},
set: function (value) {
return store = value
}
}
} * Yes, seriously. Both of these variants shaved the bundle size somehow... |
@isiahmeadows are those drops in the gzipped size? That'd explain why adding bytes can sometimes drop the overall size. |
Yes. (I specified min+gzip in the comment.)
…On Thu, Mar 15, 2018, 01:10 Pat Cavit ***@***.***> wrote:
@isiahmeadows <https://github.com/isiahmeadows> are those drops in the
gzipped size? That'd explain why adding bytes can sometimes drop the
overall size.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2095 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AERrBFyVmkseLgWtQflO5qydtmzPlX02ks5tefe_gaJpZM4SXjJe>
.
|
Since I am very surprised by the number of people advocating for it, I hardly ever used it 😅 |
I'll write a quick PR with this here soon-ish with the separate |
Fixes MithrilJS#2095
Fixes MithrilJS#2095
Fixes MithrilJS#2095
Fixes MithrilJS#2095
Fixes MithrilJS#2095
Fixes MithrilJS#2095
Okay, #2268 is up. |
I know
stream
is supposed to be m.prop's successor, but sometimes you just need a simple getter/setter function. What do you think of making amithril/prop
available to require on demand?The text was updated successfully, but these errors were encountered: