Private actions #1884
-
Hi! Thank you in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
I don't think there's a way to do that. When I needed to signal that a given view or action is an implementation detail and not part of a public API, I used the convention which predates (real) private fields and TS's |
Beta Was this translation helpful? Give feedback.
-
I agree with @elektronik2k5 and use the same convention myself. If you really don't want to expose internal actions, you can hide them in the scope similar to what you can do with import { types } from "mobx-state-tree";
let Store = types
.model({
num: types.number,
log: types.array(types.number)
})
.actions((self) => {
const _logNum = (num: number) => {
self.log.push(num);
};
return {
setNum(num: number) {
self.num = num;
_logNum(num);
}
};
});
const store = Store.create({ num: 1, log: [] });
store.setNum(2);
console.log(store); // { num: 2, log: [2] }
// Property '_logNum' does not exist on type...
store._logNum(3); |
Beta Was this translation helpful? Give feedback.
I agree with @elektronik2k5 and use the same convention myself.
If you really don't want to expose internal actions, you can hide them in the scope similar to what you can do with
volatile state
, granted they are synchronous.